示例#1
0
 public void InitContext()
 {
     // Configure Spring programmatically
     NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
     ctx = new XmlApplicationContext(
         "assembly://Spring.DataQuickStart.Tests/Spring.DataQuickStart.GenericTemplate/ExampleTests.xml");
 }
        internal static bool SetCollectionPropertyIfElementDefined(XmlElement element, ParserContext parserContext,
                                                                   ObjectDefinitionBuilder builder, string propertyName, string parentPropertyName, string parentId)
        {
            var propertyElement = element.GetSingleChildElement(propertyName.ToCamelCase());

            if (propertyElement != null)
            {
                var managedList = new ManagedList();

                foreach (XmlNode node in propertyElement)
                {
                    var parser           = NamespaceParserRegistry.GetParser(node.NamespaceURI);
                    var objectDefinition = parser.ParseElement((XmlElement)node, parserContext);

                    if (!string.IsNullOrEmpty(parentPropertyName))
                    {
                        //if the child object has a parent Property specified then set it as well for bi-directional relationships to work seamlessly.
                        objectDefinition.PropertyValues.Add(parentPropertyName, new RuntimeObjectReference(parentId));
                    }

                    managedList.Add(objectDefinition);
                }
                builder.AddPropertyValue(propertyName, managedList);

                return(true);
            }

            return(false);
        }
示例#3
0
        //[Test]
        public void BasicConfig()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.BasicConfig.xml", this.GetType()));

            Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));

            RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;

            Assert.IsNotNull(rod);

            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(ChannelFactoryObject <IContract>), rod.ObjectType);
            Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
            Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);

            ChannelFactoryObject <IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject <IContract>;

            Assert.IsNotNull(cfo);
            Assert.AreEqual(typeof(IContract), cfo.ObjectType);

            IContract contract = ctx.GetObject("channel") as IContract;

            Assert.IsNotNull(contract);
        }
示例#4
0
        //[Test]
        public void CustomProperties()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.CustomProperties.xml", this.GetType()));

            Assert.IsTrue(ctx.ContainsObjectDefinition("channel"));

            RootObjectDefinition rod = ((IObjectDefinitionRegistry)ctx).GetObjectDefinition("channel") as RootObjectDefinition;

            Assert.IsNotNull(rod);

            Assert.IsTrue(rod.HasObjectType);
            Assert.AreEqual(typeof(ChannelFactoryObject <IContract>), rod.ObjectType);
            Assert.AreEqual(1, rod.ConstructorArgumentValues.NamedArgumentValues.Count);
            Assert.AreEqual("ecn", rod.ConstructorArgumentValues.GetNamedArgumentValue("endpointConfigurationName").Value);
            Assert.IsTrue(rod.PropertyValues.Contains("Credentials.Windows.ClientCredential"));
            Assert.AreEqual("Spring\\Bruno:gnirpS", rod.PropertyValues.GetPropertyValue("Credentials.Windows.ClientCredential").Value);

            ChannelFactoryObject <IContract> cfo = ctx.GetObject("&channel") as ChannelFactoryObject <IContract>;

            Assert.IsNotNull(cfo);
            Assert.AreEqual(typeof(IContract), cfo.ObjectType);
            Assert.AreEqual("Spring", cfo.Credentials.Windows.ClientCredential.Domain);
            Assert.AreEqual("Bruno", cfo.Credentials.Windows.ClientCredential.UserName);
            Assert.AreEqual("gnirpS", cfo.Credentials.Windows.ClientCredential.Password);

            IContract contract = ctx.GetObject("channel") as IContract;

            Assert.IsNotNull(contract);
        }
        public static IApplicationContext GetContext(params string[] files)
        {
            NamespaceParserRegistry.RegisterParser(typeof(IntegrationNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(NmsNamespaceParser));

            return(new XmlApplicationContext(files));
        }
        public void Registered()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            INamespaceParser namespaceParser = NamespaceParserRegistry.GetParser("http://www.springframework.net/wcf");

            Assert.IsNotNull(namespaceParser);
            Assert.IsTrue(namespaceParser is WcfNamespaceParser);
        }
示例#7
0
        private XmlApplicationContext GetXmlApplicationContext()
        {
            NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
            XmlApplicationContext ctx = new XmlApplicationContext(
                "assembly://VisualSmart.Dao.DataQuickStart/VisualSmart.Dao.DataQuickStart.Config/Dao.xml");

            return(ctx);
        }
示例#8
0
        public void Setup()
        {
            NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
            var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(RabbitNamespaceHandlerTests).Name + "-context.xml";
            var resource     = new AssemblyResource(resourceName);

            this.objectFactory = new XmlObjectFactory(resource);
        }
        public virtual void Setup()
        {
            NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
            var resourceName =
                @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/"
                + typeof(ListenerContainerPlaceholderParserTests).Name + "-context.xml";

            this.objectFactory = new XmlApplicationContext(resourceName);
        }
示例#10
0
        public static XmlObjectFactory LoadConfig(string configConventionPrefix, int configId)
        {
            NamespaceParserRegistry.RegisterParser(typeof(RedisNamespaceHandler));

            var resourceName = $"assembly://RedisMessaging.Tests/RedisMessaging.Tests.Configs.{configConventionPrefix}/{configConventionPrefix}-{configId}.config";

            var resource = new AssemblyResource(resourceName);

            return(new XmlObjectFactory(resource));
        }
示例#11
0
        public void Setup()
        {
            NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
            var resourceName = @"assembly://Spring.Messaging.Amqp.Rabbit.Tests/Spring.Messaging.Amqp.Rabbit.Tests.Config/" + typeof(ListenerContainerParserTests).Name + "-context.xml";
            var resource     = new AssemblyResource(resourceName);

            this.objectFactory = new XmlObjectFactory(resource);

            // ((IConfigurableObjectFactory)objectFactory).setObjectExpressionResolver(new StandardObjectExpressionResolver());
        }
示例#12
0
        public void TestReceivesMessageFromChannelWithSource()
        {
            NamespaceParserRegistry.RegisterParser(typeof(IntegrationNamespaceParser));

            IApplicationContext ctx = new XmlApplicationContext(@"Channel\Config\DirectChannelParserTests.xml");

            object channel = ctx.GetObject("channel");

            Assert.That(channel.GetType(), Is.EqualTo(typeof(DirectChannel)));
        }
示例#13
0
        public static XmlObjectFactory LoadMessagingConfig()
        {
            NamespaceParserRegistry.RegisterParser(typeof(RedisNamespaceHandler));

            const string resourceName = "assembly://RedisMessaging.Tests/RedisMessaging.Tests.Configs/Messaging.config";

            var resource = new AssemblyResource(resourceName);

            return(new XmlObjectFactory(resource));
        }
        public void testRendezvous()
        {
            NamespaceParserRegistry.RegisterParser(typeof(IntegrationNamespaceParser));

            IApplicationContext ctx = new XmlApplicationContext(@"Channel\Config\RendezvousChannelParserTests.xml");

            object channel = ctx.GetObject("channel");

            Assert.That(channel.GetType(), Is.EqualTo(typeof(RendezvousChannel)));
        }
示例#15
0
        public void Registered()
        {
            Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/tx"));
            Assert.IsTrue(ctx.ContainsObjectDefinition(AopNamespaceUtils.AUTO_PROXY_CREATOR_OBJECT_NAME));

            string className  = typeof(ObjectFactoryTransactionAttributeSourceAdvisor).FullName;
            string targetName = className + ObjectDefinitionReaderUtils.GENERATED_OBJECT_NAME_SEPARATOR + "0";

            Assert.IsTrue(ctx.ContainsObjectDefinition(targetName));
        }
示例#16
0
        //[Test]
        public void WithoutId()
        {
            NamespaceParserRegistry.RegisterParser(typeof(WcfNamespaceParser));
            IApplicationContext ctx = new XmlApplicationContext(
                ReadOnlyXmlTestResource.GetFilePath("ChannelFactoryObjectDefinitionParserTests.WithoutId.xml", this.GetType()));

            IDictionary <string, IContract> channels = ctx.GetObjects <IContract>();

            Assert.AreEqual(1, channels.Count);
        }
示例#17
0
        public void SetUp()
        {
            // Configure Spring programmatically
            NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));
            IApplicationContext context = CreateContextFromXml();

            accountManager = context["accountManager"] as IAccountManager;
            CleanDb(context);
        }
示例#18
0
        private void LoadSpringConfig()
        {
            NamespaceParserRegistry.RegisterParser(typeof(DatabaseNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser));
            NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));

            string[]            param   = { "~/AppConfig/Config.xml" };
            IApplicationContext context = new XmlApplicationContext(param);

            ContextRegistry.RegisterContext(context);
        }
        static void Main(string[] args)
        {
            NamespaceParserRegistry.RegisterParser(typeof(IntegrationNamespaceParser));

            IApplicationContext ctx = new XmlApplicationContext("HelloWorld.xml");

            IChannelResolver channelResolver = new ObjectFactoryChannelResolver(ctx);
            IMessageChannel  inputChannel    = channelResolver.ResolveChannelName("inputChannel");
            IPollableChannel outputChannel   = (IPollableChannel)channelResolver.ResolveChannelName("outputChannel");

            inputChannel.Send(new StringMessage("World"));
            Console.WriteLine(outputChannel.Receive(TimeSpan.Zero).Payload);
            Console.ReadKey();
        }
        public static bool SetValueIfElementDefined(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder, string propertyName)
        {
            var childElement = element.GetSingleChildElement(propertyName.ToCamelCase());

            if (childElement != null)
            {
                var parser           = NamespaceParserRegistry.GetParser(childElement.NamespaceURI);
                var objectDefinition = parser.ParseElement(childElement, parserContext);
                builder.AddPropertyValue(propertyName, objectDefinition);

                return(true);
            }

            return(false);
        }
        public static bool AddConstructorArgValueIfElementDefined(XmlElement element, ParserContext parserContext, ObjectDefinitionBuilder builder, string childElementName)
        {
            var childElement = element.GetSingleChildElement(childElementName);

            if (childElement != null)
            {
                var parser           = NamespaceParserRegistry.GetParser(childElement.NamespaceURI);
                var inlineConnection = parser.ParseElement(childElement, parserContext);
                builder.AddConstructorArg(inlineConnection);

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Registers parsers specified in the (recommended, Spring.NET standard)
        /// <c>parsers</c> config section with the <see cref="NamespaceParserRegistry"/>.
        /// </summary>
        /// <param name="parent">
        /// The configuration settings in a corresponding parent
        /// configuration section.
        /// </param>
        /// <param name="configContext">
        /// The configuration context when called from the ASP.NET
        /// configuration system. Otherwise, this parameter is reserved and
        /// is <see langword="null"/>.
        /// </param>
        /// <param name="section">
        /// The <see cref="System.Xml.XmlNode"/> for the section.
        /// </param>
        /// <returns>
        /// This method always returns <see langword="null"/>, because parsers
        /// are registered as a side-effect of this object's execution and there
        /// is thus no need to return anything.
        /// </returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            if (section != null)
            {
                XmlNodeList parsers = ((XmlElement)section).GetElementsByTagName(ParserElementName);
                foreach (XmlElement parserElement in parsers)
                {
                    string parserTypeName = GetRequiredAttributeValue(parserElement, TypeAttributeName, section);
                    string xmlNamespace   = parserElement.GetAttribute(NamespaceAttributeName);
                    string schemaLocation = parserElement.GetAttribute(SchemaLocationAttributeName);

                    Type parserType = TypeResolutionUtils.ResolveType(parserTypeName);
                    NamespaceParserRegistry.RegisterParser(parserType, xmlNamespace, schemaLocation);
                }
            }
            return(null);
        }
        public void Registered()
        {
            Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/aop"));


            IPointcut pointcut = ctx["getDescriptionCalls"] as IPointcut;

            Assert.IsNotNull(pointcut);
            Assert.IsFalse(AopUtils.IsAopProxy(pointcut));


            ITestObject testObject = ctx["testObject"] as ITestObject;

            Assert.IsNotNull(testObject);
            Assert.IsTrue(AopUtils.IsAopProxy(testObject), "Object should be an AOP proxy");

            IAdvised advised = testObject as IAdvised;

            Assert.IsNotNull(advised);
            IAdvisor[] advisors = advised.Advisors;
            Assert.IsTrue(advisors.Length > 0, "Advisors should not be empty");
        }
        public void FixtureSetUp()
        {
            NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
            try
            {
                if (Environment.IsActive())
                {
                    // Set up broker admin for non-root user
                    this.brokerAdmin = BrokerTestUtils.GetRabbitBrokerAdmin(); // "rabbit@LOCALHOST", 5672);
                    this.brokerAdmin.StartNode();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("An error occurred during SetUp", ex);
                Assert.Fail("An error occurred during SetUp.");
            }

            if (!this.brokerFederated.Apply())
            {
                Assert.Ignore("Rabbit broker is not running. Ignoring integration test fixture.");
            }
        }
示例#25
0
        static void Main()
        {
            try
            {
                log.Info("Running....");
                NamespaceParserRegistry.RegisterParser(typeof(GemfireNamespaceParser));
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                BrokerConfiguration.Configure();

                using (IApplicationContext ctx = ContextRegistry.GetContext())
                {
                    StockForm stockForm = new StockForm();
                    Application.ThreadException += ThreadException;
                    Application.Run(stockForm);
                }
            }
            catch (Exception e)
            {
                log.Error("Spring.Interop.StockTraderSample.Client is broken.", e);
                throw;
            }
        }
 public void Registered()
 {
     Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/ems"));
 }
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(EmsNamespaceParser));
     ctx = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("EmsNamespaceHandlerTests.xml", GetType()));
 }
示例#28
0
 public void FixtureSetUp()
 {
     NamespaceParserRegistry.RegisterParser(typeof(RabbitNamespaceHandler));
 }
示例#29
0
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(GemfireNamespaceParser));
     ctx = new XmlApplicationContext(@"Config\PoolNamespaceTests.xml");
 }
 public void Setup()
 {
     NamespaceParserRegistry.RegisterParser(typeof(ContextNamespaceParser));
 }