diff --git a/src/main/java/org/springframework/data/gemfire/config/PoolParser.java b/src/main/java/org/springframework/data/gemfire/config/PoolParser.java new file mode 100644 index 00000000..eccf66a8 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/PoolParser.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010 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. + */ + +package org.springframework.data.gemfire.config; + +import org.springframework.beans.factory.BeanDefinitionStoreException; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.client.PoolFactoryBean; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +/** + * Parser for <pool;gt; definitions. + * + * @author Costin Leau + */ +class PoolParser extends AbstractSingleBeanDefinitionParser { + + protected Class getBeanClass(Element element) { + return PoolFactoryBean.class; + } + + @Override + protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) + throws BeanDefinitionStoreException { + String name = super.resolveId(element, definition, parserContext); + if (!StringUtils.hasText(name)) { + name = "gemfire-pool"; + } + return name; + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java new file mode 100644 index 00000000..6295e73e --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010 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. + */ + +package org.springframework.data.gemfire.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.client.PoolFactoryBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.gemstone.gemfire.cache.client.PoolManager; + +/** + * @author Costin Leau + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("pool-ns.xml") +public class PoolNamespaceTest { + + @Autowired + private ApplicationContext context; + + @Test + public void testBasicClient() throws Exception { + assertTrue(context.containsBean("gemfire-pool")); + assertEquals(context.getBean("gemfire-pool"), PoolManager.find("gemfire-pool")); + } + + @Test + public void testComplexPool() throws Exception { + assertTrue(context.containsBean("complex")); + PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&complex"); + assertEquals(30, TestUtils.readField("retry-attempts", pfb)); + assertEquals(6000, TestUtils.readField("free-connection-timeout", pfb)); + assertEquals(5000, TestUtils.readField("ping-interval", pfb)); + } +} diff --git a/src/test/resources/org/springframework/data/gemfire/config/pool-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/pool-ns.xml new file mode 100644 index 00000000..ee6d273a --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/pool-ns.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + \ No newline at end of file