SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.

Removed the XSD enumeration restriction on the 'type' attribute of the 'index' element definition inside the SDG XML namespace (XSD) allowing the use of property placeholders to specify the Index types on GemFire Cache Region Indexes.
This commit is contained in:
John Blum
2015-02-02 13:31:31 -08:00
parent b8bd3c69f0
commit 54821dcc66
10 changed files with 222 additions and 113 deletions

View File

@@ -55,7 +55,7 @@ public class IndexTypeConverterTest {
converter.convert("function");
}
catch (IllegalArgumentException expected) {
assertEquals("Failed to convert String (function) into an IndexType!", expected.getMessage());
assertEquals("(function) is not a valid IndexType!", expected.getMessage());
throw expected;
}
}
@@ -76,7 +76,7 @@ public class IndexTypeConverterTest {
converter.setAsText("invalid");
}
catch (IllegalArgumentException expected) {
assertEquals("Failed to convert String (invalid) into an IndexType!", expected.getMessage());
assertEquals("(invalid) is not a valid IndexType!", expected.getMessage());
throw expected;
}
finally {

View File

@@ -0,0 +1,79 @@
/*
* Copyright 2010-2013 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.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.data.gemfire.EvictionActionConverter;
import org.springframework.data.gemfire.EvictionPolicyConverter;
import org.springframework.data.gemfire.EvictionPolicyType;
import org.springframework.data.gemfire.ExpirationActionConverter;
import org.springframework.data.gemfire.IndexMaintenancePolicyConverter;
import org.springframework.data.gemfire.IndexMaintenancePolicyType;
import org.springframework.data.gemfire.IndexType;
import org.springframework.data.gemfire.IndexTypeConverter;
import org.springframework.data.gemfire.InterestPolicyConverter;
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.InterestResultPolicy;
/**
* The CustomEditorRegistrationBeanFactoryPostProcessorTest class...
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.config.CustomEditorRegistrationBeanFactoryPostProcessor
* @since 1.6.0
*/
public class CustomEditorRegistrationBeanFactoryPostProcessorTest {
@Test
public void testCustomEditorRegistration() {
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class,
"testCustomEditorRegistration.MockBeanFactory");
new CustomEditorRegistrationBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class),
eq(EvictionActionConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class),
eq(EvictionPolicyConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ExpirationAction.class),
eq(ExpirationActionConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexMaintenancePolicyType.class),
eq(IndexMaintenancePolicyConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(IndexType.class),
eq(IndexTypeConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestPolicy.class),
eq(InterestPolicyConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(InterestResultPolicy.class),
eq(InterestResultPolicyConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class),
eq(SubscriptionEvictionPolicyConverter.class));
}
}

View File

@@ -18,61 +18,70 @@ package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import javax.annotation.Resource;
import org.junit.Before;
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.test.GemfireTestApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
/**
* The IndexNamespaceTest is a test suite of test cases testing the functionality of GemFire Index creation using
* the Spring Data GemFire XML namespace (XSD).
*
* @author Costin Leau
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see org.springframework.data.gemfire.config.IndexParser
* @since 1.1.0
*/
@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SuppressWarnings("deprecation")
@ContextConfiguration(locations="index-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@SuppressWarnings({ "deprecation", "unused" })
public class IndexNamespaceTest {
private final String name = "test-index";
private static final String TEST_REGION_NAME = "TestIndexRegion";
@Autowired
private ApplicationContext context;
private Cache cache;
@Resource(name = "simple")
private Index simple;
@Resource(name = "complex")
private Index complex;
@Before
public void setUp() throws Exception {
Cache cache = (Cache) context.getBean("gemfireCache");
if (cache.getRegion(name) == null) {
cache.createRegionFactory().create("test-index");
if (cache.getRegion(TEST_REGION_NAME) == null) {
cache.createRegionFactory().create(TEST_REGION_NAME);
}
}
@Test
public void testBasicIndex() throws Exception {
Index idx = (Index) context.getBean("simple");
assertEquals("/test-index", idx.getFromClause());
assertEquals("status", idx.getIndexedExpression());
assertEquals("simple", idx.getName());
assertEquals(name, idx.getRegion().getName());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, idx.getType());
assertEquals("simple", simple.getName());
assertEquals("status", simple.getIndexedExpression());
assertEquals(Region.SEPARATOR + TEST_REGION_NAME, simple.getFromClause());
assertEquals(TEST_REGION_NAME, simple.getRegion().getName());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, simple.getType());
}
@Test
public void testComplexIndex() throws Exception {
Index idx = (Index) context.getBean("complex");
assertEquals("/test-index tsi", idx.getFromClause());
assertEquals("tsi.name", idx.getIndexedExpression());
assertEquals("complex-index", idx.getName());
assertEquals(name, idx.getRegion().getName());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, idx.getType());
assertEquals("complex-index", complex.getName());
assertEquals("tsi.name", complex.getIndexedExpression());
assertEquals(Region.SEPARATOR + TEST_REGION_NAME + " tsi", complex.getFromClause());
assertEquals(TEST_REGION_NAME, complex.getRegion().getName());
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, complex.getType());
}
}