From 4848282483d6f6bab8caeb0aedb3d9e09f5e2c00 Mon Sep 17 00:00:00 2001 From: costin Date: Tue, 31 Aug 2010 14:47:18 +0300 Subject: [PATCH] SGF-10 SGF-15 + client integration tests parsing works okay but a pool/server is still needed --- .../config/ClientRegionNamespaceTest.java | 91 +++++++++++++++++++ .../data/gemfire/config/client-ns.xml | 30 ++++++ 2 files changed, 121 insertions(+) create mode 100644 src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java create mode 100644 src/test/resources/org/springframework/data/gemfire/config/client-ns.xml diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java new file mode 100644 index 00000000..e97244a7 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -0,0 +1,91 @@ +/* + * 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.assertFalse; +import static org.junit.Assert.assertSame; +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.ClientRegionFactoryBean; +import org.springframework.data.gemfire.Interest; +import org.springframework.data.gemfire.RegexInterest; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.util.ObjectUtils; + +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.InterestResultPolicy; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; + +/** + * @author Costin Leau + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("client-ns.xml") +public class ClientRegionNamespaceTest { + + @Autowired + private ApplicationContext context; + + @Test + public void testBasicClient() throws Exception { + assertTrue(context.containsBean("simple")); + } + + @Test + public void testPublishingClient() throws Exception { + assertTrue(context.containsBean("pub")); + ClientRegionFactoryBean fb = context.getBean("&pub", ClientRegionFactoryBean.class); + assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", fb)); + assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb)); + RegionAttributes attrs = TestUtils.readField("attributes", fb); + assertFalse(attrs.getPublisher()); + } + + @Test + public void testComplexClient() throws Exception { + assertTrue(context.containsBean("complex")); + ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class); + CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); + assertFalse(ObjectUtils.isEmpty(listeners)); + assertEquals(2, listeners.length); + assertSame(listeners[0], context.getBean("c-listener")); + Interest[] ints = TestUtils.readField("interests", fb); + assertEquals(2, ints.length); + + // key interest + Interest keyInt = ints[0]; + assertTrue((Boolean) TestUtils.readField("durable", keyInt)); + assertEquals(InterestResultPolicy.KEYS, TestUtils.readField("policy", keyInt)); + assertEquals(Object.class, TestUtils.readField("key", keyInt).getClass()); + + // regex interest + RegexInterest regexInt = (RegexInterest) ints[1]; + assertFalse((Boolean) TestUtils.readField("durable", regexInt)); + assertEquals(InterestResultPolicy.KEYS_VALUES, TestUtils.readField("key", regexInt)); + assertEquals(".*", TestUtils.readField("key", regexInt)); + + } +} \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml new file mode 100644 index 00000000..d5c2f4fd --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/client-ns.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file