public void TestSchedulerAutoStartupFalse() { StaticApplicationContext context = new StaticApplicationContext(); ObjectDefinitionBuilder beanDefinition = ObjectDefinitionBuilder .GenericObjectDefinition(typeof(SchedulerFactoryObject)) .AddPropertyValue("autoStartup", false); context.RegisterObjectDefinition("scheduler", beanDefinition.ObjectDefinition); IScheduler scheduler = (IScheduler) context.GetObject("scheduler", typeof(IScheduler)); Assert.IsFalse(scheduler.IsStarted); context.Refresh(); Assert.IsFalse(scheduler.IsStarted); }
public void SunnyDay() { StaticApplicationContext ac = new StaticApplicationContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("age", "${age}"); RootObjectDefinition def = new RootObjectDefinition("${fqn}", new ConstructorArgumentValues(), pvs); ac.RegisterObjectDefinition("tb3", def); pvs = new MutablePropertyValues(); pvs.Add("age", "${age}"); pvs.Add("name", "name${var}${"); pvs.Add("spouse", new RuntimeObjectReference("${ref}")); ac.RegisterSingleton("tb1", typeof (TestObject), pvs); ConstructorArgumentValues cas = new ConstructorArgumentValues(); cas.AddIndexedArgumentValue(1, "${age}"); cas.AddGenericArgumentValue("${var}name${age}"); pvs = new MutablePropertyValues(); ArrayList friends = new ManagedList(); friends.Add("na${age}me"); friends.Add(new RuntimeObjectReference("${ref}")); pvs.Add("friends", friends); ISet someSet = new ManagedSet(); someSet.Add("na${age}me"); someSet.Add(new RuntimeObjectReference("${ref}")); pvs.Add("someSet", someSet); IDictionary someDictionary = new ManagedDictionary(); someDictionary["key1"] = new RuntimeObjectReference("${ref}"); someDictionary["key2"] = "${age}name"; MutablePropertyValues innerPvs = new MutablePropertyValues(); someDictionary["key3"] = new RootObjectDefinition(typeof (TestObject), innerPvs); someDictionary["key4"] = new ChildObjectDefinition("tb1", innerPvs); pvs.Add("someMap", someDictionary); RootObjectDefinition definition = new RootObjectDefinition(typeof (TestObject), cas, pvs); ac.DefaultListableObjectFactory.RegisterObjectDefinition("tb2", definition); pvs = new MutablePropertyValues(); pvs.Add("Properties", "<spring-config><add key=\"age\" value=\"98\"/><add key=\"var\" value=\"${m}var\"/><add key=\"ref\" value=\"tb2\"/><add key=\"m\" value=\"my\"/><add key=\"fqn\" value=\"Spring.Objects.TestObject, Spring.Core.Tests\"/></spring-config>"); ac.RegisterSingleton("configurer", typeof (PropertyPlaceholderConfigurer), pvs); ac.Refresh(); TestObject tb1 = (TestObject) ac.GetObject("tb1"); TestObject tb2 = (TestObject) ac.GetObject("tb2"); TestObject tb3 = (TestObject) ac.GetObject("tb3"); Assert.AreEqual(98, tb1.Age); Assert.AreEqual(98, tb2.Age); Assert.AreEqual(98, tb3.Age); Assert.AreEqual("namemyvar${", tb1.Name); Assert.AreEqual("myvarname98", tb2.Name); Assert.AreEqual(tb2, tb1.Spouse); Assert.AreEqual(2, tb2.Friends.Count); IEnumerator ie = tb2.Friends.GetEnumerator(); ie.MoveNext(); Assert.AreEqual("na98me", ie.Current); ie.MoveNext(); Assert.AreEqual(tb2, ie.Current); Assert.AreEqual(2, tb2.SomeSet.Count); Assert.IsTrue(tb2.SomeSet.Contains("na98me")); Assert.IsTrue(tb2.SomeSet.Contains(tb2)); Assert.AreEqual(4, tb2.SomeMap.Count); Assert.AreEqual(tb2, tb2.SomeMap["key1"]); Assert.AreEqual("98name", tb2.SomeMap["key2"]); TestObject inner1 = (TestObject) tb2.SomeMap["key3"]; TestObject inner2 = (TestObject) tb2.SomeMap["key4"]; Assert.AreEqual(0, inner1.Age); Assert.AreEqual(null, inner1.Name); Assert.AreEqual(98, inner2.Age); Assert.AreEqual("namemyvar${", inner2.Name); }
public void TestSchedulerAutoStartsOnContextRefreshedEventByDefault() { StaticApplicationContext context = new StaticApplicationContext(); context.RegisterObjectDefinition("scheduler", new RootObjectDefinition(typeof (SchedulerFactoryObject))); IScheduler scheduler = (IScheduler) context.GetObject("scheduler", typeof (IScheduler)); Assert.IsFalse(scheduler.IsStarted); context.Refresh(); Assert.IsTrue(scheduler.IsStarted); }