public void ProbesSharedStateFactories()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            ISharedStateFactory ssf1 = A.Fake <ISharedStateFactory>();
            ISharedStateFactory ssf2 = A.Fake <ISharedStateFactory>();
            ISharedStateFactory ssf3 = A.Fake <ISharedStateFactory>();
            ISharedStateFactory ssf4 = A.Fake <ISharedStateFactory>();
            IDictionary         ssf3ProvidedState = new Hashtable();

            SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();

            ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1, ssf2, ssf3, ssf4 };
            of.RegisterSingleton("ssap", ssap);

            ISharedStateAware ssa = A.Fake <ISharedStateAware>();

            // Ensure we iterate over configured SharedStateFactories until
            // the first provider is found that
            // a) true == provider.CanProvideState( instance, name )
            // b) null != provider.GetSharedState( instance, name )

            A.CallTo(() => ssa.SharedState).Returns(null).Once();
            A.CallTo(() => ssf1.CanProvideState(ssa, "pageName")).Returns(false).Once();
            A.CallTo(() => ssf2.CanProvideState(ssa, "pageName")).Returns(true).Once();
            A.CallTo(() => ssf2.GetSharedStateFor(ssa, "pageName")).Returns(null);
            A.CallTo(() => ssf3.CanProvideState(ssa, "pageName")).Returns(true).Once();
            A.CallTo(() => ssf3.GetSharedStateFor(ssa, "pageName")).Returns(ssf3ProvidedState).Once();

            ssap.PostProcessBeforeInitialization(ssa, "pageName");

            Assert.That(Equals(ssa.SharedState, ssf3ProvidedState));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericApplicationContext"/> class.
 /// </summary>
 /// <param name="name">The name of the application context.</param>
 /// <param name="caseSensitive">if set to <c>true</c> names in the context are case sensitive.</param>
 /// <param name="parent">The parent application context.</param>
 /// <param name="objectFactory">The object factory to use for this context</param>
 public GenericApplicationContext(string name, bool caseSensitive, IApplicationContext parent, DefaultListableObjectFactory objectFactory)
     : base(name, caseSensitive, parent)
 {
     AssertUtils.ArgumentNotNull(objectFactory, "objectFactory", "ObjectFactory must not be null");
     this.objectFactory = objectFactory;
     this.objectFactory.ParentObjectFactory = base.GetInternalParentObjectFactory();
 }
        private void InitFactory(DefaultListableObjectFactory factory)
        {
            Console.WriteLine("init factory");
            RootObjectDefinition tee = new RootObjectDefinition(typeof(Tee), true);

            tee.IsLazyInit = true;
            ConstructorArgumentValues teeValues = new ConstructorArgumentValues();

            teeValues.AddGenericArgumentValue("test");
            tee.ConstructorArgumentValues = teeValues;

            RootObjectDefinition      bar       = new RootObjectDefinition(typeof(BBar), false);
            ConstructorArgumentValues barValues = new ConstructorArgumentValues();

            barValues.AddGenericArgumentValue(new RuntimeObjectReference("tee"));
            barValues.AddGenericArgumentValue(5);
            bar.ConstructorArgumentValues = barValues;

            RootObjectDefinition  foo       = new RootObjectDefinition(typeof(FFoo), false);
            MutablePropertyValues fooValues = new MutablePropertyValues();

            fooValues.Add("i", 5);
            fooValues.Add("bar", new RuntimeObjectReference("bar"));
            fooValues.Add("copy", new RuntimeObjectReference("bar"));
            fooValues.Add("s", "test");
            foo.PropertyValues = fooValues;

            factory.RegisterObjectDefinition("foo", foo);
            factory.RegisterObjectDefinition("bar", bar);
            factory.RegisterObjectDefinition("tee", tee);
        }
        public void SetUp()
        {
            this.objectFactory = new DefaultListableObjectFactory();
            IObjectDefinitionReader reader = new XmlObjectDefinitionReader(this.objectFactory);

            reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("collectionMergingGeneric.xml", GetType()));
        }
Exemplo n.º 5
0
        public void MakeSurePrototypeTargetIsNotNeedlesslyCreatedDuringInitialization_Integration()
        {
            try
            {
                RootObjectDefinition advice = new RootObjectDefinition(typeof(NopInterceptor));
                // prototype target...
                RootObjectDefinition target = new RootObjectDefinition(typeof(InstantiationCountingCommand), false);

                DefaultListableObjectFactory ctx = new DefaultListableObjectFactory();
                ctx.RegisterObjectDefinition("advice", advice);
                ctx.RegisterObjectDefinition("prototype", target);

                ProxyFactoryObject fac = new ProxyFactoryObject();
                fac.ProxyInterfaces  = new string[] { typeof(ICommand).FullName };
                fac.IsSingleton      = false;
                fac.InterceptorNames = new string[] { "advice", "prototype" };
                fac.ObjectFactory    = ctx;

                Assert.AreEqual(0, InstantiationCountingCommand.NumberOfInstantiations,
                                "Prototype target instance is being (needlessly) created during PFO initialization.");
                fac.GetObject();
                Assert.AreEqual(1, InstantiationCountingCommand.NumberOfInstantiations, "Expected 1 inst");
                fac.GetObject();
                Assert.AreEqual(2, InstantiationCountingCommand.NumberOfInstantiations);
            }
            finally
            {
                InstantiationCountingCommand.NumberOfInstantiations = 0;
            }
        }
        public void DoesNotAcceptInfrastructureAdvisorsDuringScanning()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            GenericObjectDefinition infrastructureAdvisorDefinition = new GenericObjectDefinition();

            infrastructureAdvisorDefinition.ObjectType = typeof(TestAdvisor);
            infrastructureAdvisorDefinition.PropertyValues.Add("Name", "InfrastructureAdvisor");
            infrastructureAdvisorDefinition.Role = ObjectRole.ROLE_INFRASTRUCTURE;
            of.RegisterObjectDefinition("infrastructure", infrastructureAdvisorDefinition);

            GenericObjectDefinition regularAdvisorDefinition = new GenericObjectDefinition();

            regularAdvisorDefinition.ObjectType = typeof(TestAdvisor);
            regularAdvisorDefinition.PropertyValues.Add("Name", "RegularAdvisor");
//            regularAdvisorDefinition.Role = ObjectRole.ROLE_APPLICATION;
            of.RegisterObjectDefinition("regular", regularAdvisorDefinition);

            TestAdvisorAutoProxyCreator apc = new TestAdvisorAutoProxyCreator();

            apc.ObjectFactory = of;
            object[] advisors = apc.GetAdvicesAndAdvisorsForObject(typeof(object), "dummyTarget");
            Assert.AreEqual(1, advisors.Length);
            Assert.AreEqual("RegularAdvisor", ((TestAdvisor)advisors[0]).Name);

            Assert.AreEqual(1, apc.CheckedAdvisors.Count);
            Assert.AreEqual("regular", apc.CheckedAdvisors[0]);
        }
        public void IgnoresAlreadyPopulatedState()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            MockRepository      mocks = new MockRepository();
            ISharedStateFactory ssf1  = (ISharedStateFactory)mocks.CreateMock(typeof(ISharedStateFactory));
            ISharedStateAware   ssa   = (ISharedStateAware)mocks.DynamicMock(typeof(ISharedStateAware));

            SharedStateAwareProcessor ssap = new SharedStateAwareProcessor();

            ssap.SharedStateFactories = new ISharedStateFactory[] { ssf1 };
            of.RegisterSingleton("ssap", ssap);

            using (Record(mocks))
            {
                // preset SharedState - ssap must ignore it
                Expect.Call(ssa.SharedState).Return(new Hashtable());
                // expect nothing else!
            }

            using (Playback(mocks))
            {
                ssap.PostProcessBeforeInitialization(ssa, "myPage");
            }
        }
Exemplo n.º 8
0
        public void ThrowsTypeLoadExceptionIfProxyInterfacesValueIsSpecifiedInsteadOfListElement()
        {
            using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
            {
                XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' xmlns:r='http://www.springframework.net/remoting'>  
    
    <r:saoExporter id='ISimpleCounterExporter' targetName='ISimpleCounterProxy' serviceName='RemotedSaoCounterProxy' />
    
    <object id='ISimpleCounter' type='Spring.Remoting.SimpleCounter, Spring.Services.Tests' />

    <object id='ISimpleCounterProxy' type='Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop'>
        <property name='proxyInterfaces' value='Spring.Remoting.ISimpleCounter, Spring.Services.Tests' />
        <property name='target' ref='ISimpleCounter'/>
    </object>
</objects>
"));
                try
                {
                    SaoExporter saoExporter = (SaoExporter)of.GetObject("ISimpleCounterExporter");
                    Assert.Fail();
                }
                catch (ObjectCreationException oce)
                {
                    TypeLoadException tle = (TypeLoadException)oce.GetBaseException();
                    Assert.AreEqual("Could not load type from string value ' Spring.Services.Tests'.", tle.Message);
                }
            }
        }
Exemplo n.º 9
0
        public void SingletonProxyWithPrototypeTargetCreatesTargetOnlyOnce()
        {
            try
            {
                RootObjectDefinition advice = new RootObjectDefinition(typeof(NopInterceptor));
                // prototype target...
                RootObjectDefinition target = new RootObjectDefinition(typeof(InstantiationCountingCommand), false);

                DefaultListableObjectFactory ctx = new DefaultListableObjectFactory();
                ctx.RegisterObjectDefinition("advice", advice);
                ctx.RegisterObjectDefinition("prototype", target);

                ProxyFactoryObject fac = new ProxyFactoryObject();
                fac.ProxyInterfaces  = new string[] { typeof(ICommand).FullName };
                fac.IsSingleton      = true;
                fac.InterceptorNames = new string[] { "advice", "prototype" };
                fac.ObjectFactory    = ctx;

                Assert.AreEqual(0, InstantiationCountingCommand.NumberOfInstantiations, "First Call");
                fac.GetObject();
                Assert.AreEqual(1, InstantiationCountingCommand.NumberOfInstantiations, "Second Call");
                fac.GetObject();
                Assert.AreEqual(1, InstantiationCountingCommand.NumberOfInstantiations, "Third Call");
            }

            finally
            {
                InstantiationCountingCommand.NumberOfInstantiations = 0;
            }
        }
Exemplo n.º 10
0
        public void CanExportFromFactoryObjectIfObjectTypeIsInterface()
        {
            using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
            {
                MockRepository mocks = new MockRepository();
                IFactoryObject simpleCounterFactory = (IFactoryObject)mocks.DynamicMock(typeof(IFactoryObject));
                Expect.Call(simpleCounterFactory.ObjectType).Return(typeof(ISimpleCounter));
                Expect.Call(simpleCounterFactory.IsSingleton).Return(true);
                Expect.Call(simpleCounterFactory.GetObject()).Return(new SimpleCounter());

                mocks.ReplayAll();

                of.RegisterSingleton("simpleCounter", simpleCounterFactory);
                SaoExporter saoExporter = new SaoExporter();
                saoExporter.ObjectFactory = of;
                saoExporter.TargetName    = "simpleCounter";
                saoExporter.ServiceName   = "RemotedSaoCallCounter";
                saoExporter.AfterPropertiesSet();
                of.RegisterSingleton("simpleCounterExporter", saoExporter); // also tests SaoExporter.Dispose()!

                AssertExportedService(saoExporter.ServiceName, 2);

                mocks.VerifyAll();
            }
        }
Exemplo n.º 11
0
        public void SunnyDayReplaceMethod_WithArgumentAcceptingReplacer()
        {
            RootObjectDefinition replacerDef = new RootObjectDefinition(typeof(NewsFeedFactory));

            RootObjectDefinition   managerDef  = new RootObjectDefinition(typeof(NewsFeedManagerWith_Replace_MethodThatTakesArguments));
            ReplacedMethodOverride theOverride = new ReplacedMethodOverride("CreateNewsFeed", "replacer");

            // we must specify parameter type fragments...
            theOverride.AddTypeIdentifier(typeof(string).FullName);
            managerDef.MethodOverrides.Add(theOverride);

            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();

            factory.RegisterObjectDefinition("manager", managerDef);
            factory.RegisterObjectDefinition("replacer", replacerDef);
            NewsFeedManagerWith_Replace_MethodThatTakesArguments manager = (NewsFeedManagerWith_Replace_MethodThatTakesArguments)factory["manager"];
            NewsFeed feed1 = manager.CreateNewsFeed("So sad... to be all alone in the world");

            Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
            Assert.AreEqual("So sad... to be all alone in the world", feed1.Name);
            NewsFeed feed2 = manager.CreateNewsFeed("Oh Muzzy!");

            // NewsFeedFactory always yields a new NewsFeed (see class definition below)...
            Assert.IsFalse(ReferenceEquals(feed1, feed2));
        }
Exemplo n.º 12
0
        public void LookupMethodWithNullMethodInstantiatedWithCtorArg()
        {
            RootObjectDefinition feedDef = new RootObjectDefinition(typeof(NewsFeed));

            feedDef.IsSingleton = false;
            feedDef.PropertyValues.Add("name", "Bingo");

            RootObjectDefinition managerDef = new RootObjectDefinition(typeof(ReturnsNullNewsFeedManager));

            managerDef.MethodOverrides.Add(new LookupMethodOverride("CreateNewsFeed", "feed"));
            managerDef.ConstructorArgumentValues.AddNamedArgumentValue("name", "Bingo");

            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();

            factory.RegisterObjectDefinition("manager", managerDef);
            factory.RegisterObjectDefinition("feed", feedDef);
            ReturnsNullNewsFeedManager manager = (ReturnsNullNewsFeedManager)factory["manager"];

            Assert.AreEqual("Bingo", manager.Name);
            NewsFeed feed1 = manager.CreateNewsFeed();

            Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
            NewsFeed feed2 = manager.CreateNewsFeed();

            // assert that the object (prototype) is definitely being looked up each time...
            Assert.IsFalse(ReferenceEquals(feed1, feed2));
        }
Exemplo n.º 13
0
        public void LookupMethodWithNullMethod()
        {
            try
            {
                RootObjectDefinition feedDef = new RootObjectDefinition(typeof(NewsFeed));
                feedDef.IsSingleton = false;
                feedDef.PropertyValues.Add("name", "Bingo");

                RootObjectDefinition managerDef = new RootObjectDefinition(typeof(ReturnsNullNewsFeedManager));
                managerDef.MethodOverrides.Add(new LookupMethodOverride("CreateNewsFeed", "feed"));

                DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
                factory.RegisterObjectDefinition("manager", managerDef);
                factory.RegisterObjectDefinition("feed", feedDef);
                INewsFeedManager manager = (INewsFeedManager)factory["manager"];
                NewsFeed         feed1   = manager.CreateNewsFeed();
                Assert.IsNotNull(feed1, "The CreateNewsFeed() method is not being replaced.");
                NewsFeed feed2 = manager.CreateNewsFeed();
                // assert that the object (prototype) is definitely being looked up each time...
                Assert.IsFalse(ReferenceEquals(feed1, feed2));
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("ex = {0}", ex);
            }
        }
Exemplo n.º 14
0
        [Ignore] //this test cannot co-exist with AutoRegistersAllWellknownNamespaceParsers b/c that test will have already loaded the Spring.Data ass'y
        public void AutoRegistersWellknownNamespaceParser()
        {
            try
            {
                Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                foreach (Assembly assembly in loadedAssemblies)
                {
                    if (assembly.GetName(true).Name.StartsWith("Spring.Data"))
                    {
                        Assert.Fail("Spring.Data is already loaded - this test checks if it gets loaded during xml parsing");
                    }
                }

                NamespaceParserRegistry.Reset();

                DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
                XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
                                                    <objects xmlns='http://www.springframework.net' 
                                                             xmlns:tx='http://www.springframework.net/tx'>  
                                                          <tx:attribute-driven />
                                                    </objects>
                                                    "));
                object apc = of.GetObject(AopNamespaceUtils.AUTO_PROXY_CREATOR_OBJECT_NAME);
                Assert.NotNull(apc);
            }
            finally
            {
                NamespaceParserRegistry.Reset();
            }
        }
Exemplo n.º 15
0
        protected void SetUp()
        {
            parent = new DefaultListableObjectFactory();
            IDictionary m = new Hashtable();

            m["name"] = "Albert";
            parent.RegisterObjectDefinition("father", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m)));
            m         = new Hashtable();
            m["name"] = "Roderick";
            parent.RegisterObjectDefinition("rod", new RootObjectDefinition(typeof(TestObject), new MutablePropertyValues(m)));

            // for testing dynamic ctor arguments + parent.GetObject() call propagation
            parent.RegisterObjectDefinition("namedfather", new RootObjectDefinition(typeof(TestObject), false));
            parent.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(TestObject), false));

            // add unsupported IObjectDefinition implementation...
            UnsupportedObjectDefinitionImplementation unsupportedDefinition = new UnsupportedObjectDefinitionImplementation();

            parent.RegisterObjectDefinition("unsupportedDefinition", unsupportedDefinition);

            XmlObjectFactory factory;

            factory = new XmlObjectFactory(new ReadOnlyXmlTestResource("test.xml", GetType()), parent);

            // TODO: should this be allowed?
            //this.factory.RegisterObjectDefinition("typedfather", new RootObjectDefinition(typeof(object), false));
            factory.AddObjectPostProcessor(new AnonymousClassObjectPostProcessor());
            factory.AddObjectPostProcessor(new LifecycleObject.PostProcessor());

            factory.PreInstantiateSingletons();
            base.ObjectFactory = factory;
        }
        public void ProxyTransparentProxy()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues();

            ctorArgs.AddNamedArgumentValue("objectType", typeof(ITestObject));
            of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(TransparentProxyFactory), ctorArgs, null));

            TestAutoProxyCreator apc = new TestAutoProxyCreator(of);

            of.AddObjectPostProcessor(apc);

            ITestObject o = of.GetObject("bar") as ITestObject;

            Assert.IsTrue(AopUtils.IsAopProxy(o));

            // ensure interceptors get called
            o.Foo();
            Assert.AreEqual(1, apc.NopInterceptor.Count);
            IAdvised advised = (IAdvised)o;

            // ensure target was called
            object target = advised.TargetSource.GetTarget();

            Assert.AreEqual(1, TransparentProxyFactory.GetRealProxy(target).Count);
        }
        /// <summary>
        /// Load all registered configuration into spring. This method should only be called internally by the FluentApplicationContext, i.e. you shouldn't call it.
        /// </summary>
        /// <param name="objectFactory">The object factory.</param>
        public static void LoadConfiguration(DefaultListableObjectFactory objectFactory)
        {
            // This check is mainly for backward compability and avoid people trying to register their configuration twice.
            if (!_configurationRegistry.ContainsConfiguration())
            {
                if (_assembliesList.Count == 0)
                {
                    _assembliesList.Add(() => AppDomain.CurrentDomain.GetAssemblies());
                }

                IList <Type> applicationContextConfigurerTypes = new List <Type>();
                // only load the configuration once (in case the assembly was registered twice)
                foreach (Type type in from assemblies in _assembliesList
                         from assembly in assemblies()
                         from type in assembly.GetTypes()
                         where type.GetInterfaces().Contains(typeof(ICanConfigureApplicationContext))
                         where !applicationContextConfigurerTypes.Contains(type)
                         select type)
                {
                    applicationContextConfigurerTypes.Add(type);
                }
                // load each class containing configuration.
                foreach (ICanConfigureApplicationContext contextConfigurer in
                         applicationContextConfigurerTypes.Select(applicationContextConfigurerType => (ICanConfigureApplicationContext)Activator.CreateInstance(applicationContextConfigurerType)))
                {
                    contextConfigurer.Configure();
                }
            }

            _configurationRegistry.LoadObjectDefinitions(objectFactory);
        }
        public void Setup()
        {
            objectFactory = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(objectFactory);

            reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("objectNameGeneration.xml", GetType()));
        }
Exemplo n.º 19
0
        public void ParsesAutowireCandidate()
        {
            DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);

            reader.LoadObjectDefinitions(new StringResource(
                                             @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' default-autowire-candidates='test1*,test4*'>  
	<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' />
	<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='false' />
	<object id='test3' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='true' />
	<object id='test4' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
	<object id='test5' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
</objects>
"));
            var od = (AbstractObjectDefinition)of.GetObjectDefinition("test1");

            Assert.That(od.IsAutowireCandidate, Is.True, "No attribute set should default to true");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
            Assert.That(od.IsAutowireCandidate, Is.False, "Specifically attribute set to false should set to false");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test3");
            Assert.That(od.IsAutowireCandidate, Is.True, "Specifically attribute set to true should set to false");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test4");
            Assert.That(od.IsAutowireCandidate, Is.True, "Attribute set to default should check pattern and return true");

            od = (AbstractObjectDefinition)of.GetObjectDefinition("test5");
            Assert.That(od.IsAutowireCandidate, Is.False, "Attribute set to default should check pattern and return false");
        }
Exemplo n.º 20
0
        public void ParsesObjectAttributes()
        {
            DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);

            reader.LoadObjectDefinitions(new StringResource(
                                             @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='false' abstract='true' />
	<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='true' abstract='false' lazy-init='true' 
        autowire='no' dependency-check='simple'
        depends-on='test1' 
        init-method='init'
        destroy-method='destroy'
    />
</objects>
"));
            AbstractObjectDefinition od1 = (AbstractObjectDefinition)of.GetObjectDefinition("test1");

            Assert.IsFalse(od1.IsSingleton);
            Assert.IsTrue(od1.IsAbstract);
            Assert.IsFalse(od1.IsLazyInit);

            AbstractObjectDefinition od2 = (AbstractObjectDefinition)of.GetObjectDefinition("test2");

            Assert.IsTrue(od2.IsSingleton);
            Assert.IsFalse(od2.IsAbstract);
            Assert.IsTrue(od2.IsLazyInit);
            Assert.AreEqual(AutoWiringMode.No, od2.AutowireMode);
            Assert.AreEqual("init", od2.InitMethodName);
            Assert.AreEqual("destroy", od2.DestroyMethodName);
            Assert.AreEqual(1, od2.DependsOn.Count);
            Assert.AreEqual("test1", od2.DependsOn[0]);
            Assert.AreEqual(DependencyCheckingMode.Simple, od2.DependencyCheck);
        }
Exemplo n.º 21
0
        public void ParsesNonDefaultNamespace()
        {
            try
            {
                NamespaceParserRegistry.Reset();

                DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
                XmlObjectDefinitionReader    reader = new XmlObjectDefinitionReader(of);
                reader.LoadObjectDefinitions(new StringResource(
                                                 @"<?xml version='1.0' encoding='UTF-8' ?>
<core:objects xmlns:core='http://www.springframework.net'>  
	<core:object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests'>
        <core:property name='Sibling'>
            <core:object type='Spring.Objects.TestObject, Spring.Core.Tests' />
        </core:property>
    </core:object>
</core:objects>
"));
                TestObject test2 = (TestObject)of.GetObject("test2");
                Assert.AreEqual(typeof(TestObject), test2.GetType());
                Assert.IsNotNull(test2.Sibling);
            }
            finally
            {
                NamespaceParserRegistry.Reset();
            }
        }
Exemplo n.º 22
0
            private static NamedObjectDefinition Find(string url, string objectName)
            {
                DefaultListableObjectFactory of  = new DefaultListableObjectFactory();
                RootObjectDefinition         rod = new RootObjectDefinition(typeof(Type1));

                of.RegisterObjectDefinition(objectName, rod);

                return(FindWebObjectDefinition(url, of));
            }
        public void OrderOfKnownProcessorInterfaces()
        {
            DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)this._context.ObjectFactory;
            RootObjectDefinition         def;

            def = new RootObjectDefinition(typeof(EverythingAwareObjectPostProcessor));
            objectFactory.RegisterObjectDefinition("everythingAwareObjectPostProcessor", def);
            _context.Refresh();
        }
Exemplo n.º 24
0
 protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet)
 {
     if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null)
     {
         DefaultListableObjectFactory of = new DefaultListableObjectFactory();
         of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor)));
         of.RegisterSingleton("pet", pet);
         pf.AddAdvice((PersistenceExceptionTranslationInterceptor)of.GetObject("peti"));
     }
 }
Exemplo n.º 25
0
        public void Can_Create_Custom_Scan_Routine()
        {
            var scanner  = new ScanOverridingAssemblyObjectDefinitionScanner();
            var registry = new DefaultListableObjectFactory();

            scanner.ScanAndRegisterTypes(registry);
            Assert.That(registry.ObjectDefinitionCount, Is.EqualTo(1), "found multiple definitions");
            Assert.That(registry.GetObject <ComponentScan.ScanComponentsAndAddToContext.ConfigurationImpl>(), Is.Not.Null,
                        "correct single defintion was not registered");
        }
        public void CanCreateHostTwice()
        {
            DefaultListableObjectFactory of = new DefaultListableObjectFactory();

            string svcRegisteredName = System.Guid.NewGuid().ToString();

            of.RegisterObjectDefinition(svcRegisteredName, new RootObjectDefinition(new RootObjectDefinition(typeof(Service))));
            SpringServiceHost ssh  = new SpringServiceHost(svcRegisteredName, of, true);
            SpringServiceHost ssh1 = new SpringServiceHost(svcRegisteredName, of, true);
        }
Exemplo n.º 27
0
 public void BailsIfTargetNotFound()
 {
     using (DefaultListableObjectFactory of = new DefaultListableObjectFactory())
     {
         SaoExporter saoExporter = new SaoExporter();
         saoExporter.ObjectFactory = of;
         saoExporter.TargetName    = "DOESNOTEXIST";
         saoExporter.ServiceName   = "RemotedSaoSingletonCounter";
         saoExporter.AfterPropertiesSet();
     }
 }
Exemplo n.º 28
0
        public void ThrowsObjectDefinitionStoreExceptionOnErrorDuringObjectDefinitionRegistration()
        {
            DefaultListableObjectFactory of     = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader    reader = new TestXmlObjectDefinitionReader(of);

            reader.LoadObjectDefinitions(new StringResource(
                                             @"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>  
	<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' />
</objects>
"));
        }
        public void DefaultObjectFactoryProcessorsDontGetAddedTwice()
        {
            MockApplicationContext       myContext     = new MockApplicationContext("myContext");
            DefaultListableObjectFactory objectFactory = (DefaultListableObjectFactory)myContext.ObjectFactory;

            Assert.AreEqual(0, objectFactory.ObjectPostProcessorCount);
            myContext.Refresh();
            int defaultProcessors = objectFactory.ObjectPostProcessors.Count;

            myContext.Refresh();
            Assert.AreEqual(defaultProcessors, objectFactory.ObjectPostProcessors.Count);
        }
Exemplo n.º 30
0
        public virtual void StaticEventWiring()
        {
            DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
            XmlObjectDefinitionReader    reader  = new XmlObjectDefinitionReader(factory);

            reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("event-wiring.xml", GetType()));
            TestEventHandler staticHandler = factory["staticEventListener"] as TestEventHandler;

            // raise the event... handlers should be notified at this point (obviously)
            TestObject.OnStaticClick();
            Assert.IsTrue(staticHandler.EventWasHandled,
                          "The instance handler did not get notified when the static event was raised (and was probably not wired up in the first place).");
        }