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

Removed the 'subscriptionPolicyType' XSD simple-type definition and subsequently, all Subscription policy enumeration restrictions on SDG Region elements in the SDG XML namespace (e.g. gfe:partitioned-region) that declare and define a Subscription policy.  Renamed SubscriptionType to InterestPolicyType along with the associated test suite class.  Renamed the SubscriptionTypeConverter class to InterestPolicyConverter along with the associated test suite class.  Created the RegionSubscriptionAttributesNamespaceTest class to test the configuration of Subscription on GemFire Regions in the SDG XML namespace using various settings and property placeholders.
This commit is contained in:
John Blum
2015-01-23 16:15:27 -08:00
parent 319442b446
commit ecbd4fd232
16 changed files with 511 additions and 340 deletions

View File

@@ -64,7 +64,7 @@ public class EvictionActionTypeTest {
}
@Test
public void testValueOfWithInvalidValue() {
public void testValueOfWithNull() {
assertNull(EvictionActionType.valueOf((EvictionAction) null));
}
@@ -77,7 +77,7 @@ public class EvictionActionTypeTest {
}
@Test
public void testValueOfIgnoreCaseWithInvalidValue() {
public void testValueOfIgnoreCaseWithInvalidValues() {
assertNull(EvictionActionType.valueOfIgnoreCase("REMOTE_DESTROY"));
assertNull(EvictionActionType.valueOfIgnoreCase("All"));
assertNull(EvictionActionType.valueOfIgnoreCase(" none "));

View File

@@ -57,8 +57,8 @@ public class ExpirationActionTypeTest {
@Test
public void testDefault() {
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
assertEquals(ExpirationAction.INVALIDATE, ExpirationActionType.DEFAULT.getExpirationAction());
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
}
@Test

View File

@@ -17,22 +17,26 @@
package org.springframework.data.gemfire;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Test;
import com.gemstone.gemfire.cache.InterestPolicy;
/**
* The SubscriptionTypeConverterTest class is a test suite of test cases testing the contract and functionality
* of the SubscriptionTypeConverter class.
* The InterestPolicyConverterTest class is a test suite of test cases testing the contract and functionality
* of the InterestPolicyConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.SubscriptionTypeConverter
* @since 1.5.0
* @see org.springframework.data.gemfire.InterestPolicyConverter
* @see com.gemstone.gemfire.cache.InterestPolicy
* @since 1.6.0
*/
public class SubscriptionTypeConverterTest {
public class InterestPolicyConverterTest {
private SubscriptionTypeConverter converter = new SubscriptionTypeConverter();
private InterestPolicyConverter converter = new InterestPolicyConverter();
@After
public void tearDown() {
@@ -41,18 +45,19 @@ public class SubscriptionTypeConverterTest {
@Test
public void testConvert() {
assertEquals(SubscriptionType.ALL, converter.convert("all"));
assertEquals(SubscriptionType.CACHE_CONTENT, converter.convert("Cache_Content"));
assertEquals(SubscriptionType.DEFAULT, converter.convert("DeFault"));
assertEquals(InterestPolicy.ALL, converter.convert("all"));
assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("Cache_Content"));
assertEquals(InterestPolicy.CACHE_CONTENT, converter.convert("CACHE_ConTent"));
assertEquals(InterestPolicy.ALL, converter.convert("ALL"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertWithInvalidValue() {
public void testConvertIllegalValueValue() {
try {
converter.convert("invalid");
}
catch (IllegalArgumentException expected) {
assertEquals("Source (invalid) is not a valid SubscriptionType!", expected.getMessage());
assertEquals("(invalid) is not a valid InterestPolicy!", expected.getMessage());
throw expected;
}
}
@@ -60,20 +65,24 @@ public class SubscriptionTypeConverterTest {
@Test
public void testSetAsText() {
converter.setAsText("aLl");
assertEquals(SubscriptionType.ALL, converter.getValue());
converter.setAsText("CACHE_content");
assertEquals(SubscriptionType.CACHE_CONTENT, converter.getValue());
assertEquals(InterestPolicy.ALL, converter.getValue());
converter.setAsText("Cache_CoNTeNT");
assertEquals(InterestPolicy.CACHE_CONTENT, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithInvalidValue() {
try {
assertNull(converter.getValue());
converter.setAsText("none");
}
catch (IllegalArgumentException expected) {
assertEquals("Source (none) is not a valid SubscriptionType!", expected.getMessage());
assertEquals("(none) is not a valid InterestPolicy!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,100 @@
/*
* 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import com.gemstone.gemfire.cache.InterestPolicy;
/**
* The InterestPolicyTypeTest class is a test suite of test cases testing the contract and functionality
* of the InterestPolicyType enum.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.InterestPolicyType
* @see com.gemstone.gemfire.cache.InterestPolicy
* @since 1.6.0
*/
public class InterestPolicyTypeTest {
@Test
public void testStaticGetInterestPolicy() {
assertEquals(InterestPolicy.ALL, InterestPolicyType.getInterestPolicy(InterestPolicyType.ALL));
assertEquals(InterestPolicy.CACHE_CONTENT, InterestPolicyType.getInterestPolicy(InterestPolicyType.CACHE_CONTENT));
}
@Test
public void testStaticGetInterestPolicyWithNull() {
assertNull(InterestPolicyType.getInterestPolicy(null));
}
@Test
public void testGetInterestPolicy() {
assertEquals(InterestPolicy.ALL, InterestPolicyType.ALL.getInterestPolicy());
assertEquals(InterestPolicy.CACHE_CONTENT, InterestPolicyType.CACHE_CONTENT.getInterestPolicy());
}
@Test
public void testDefault() {
assertEquals(InterestPolicy.DEFAULT, InterestPolicyType.valueOf(InterestPolicy.DEFAULT).getInterestPolicy());
assertEquals(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.DEFAULT);
}
@Test
public void testValueOfInterestPolicies() {
try {
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
InterestPolicy interestPolicy = InterestPolicy.fromOrdinal(ordinal);
InterestPolicyType interestPolicyType = InterestPolicyType.valueOf(interestPolicy);
assertNotNull(interestPolicyType);
assertEquals(interestPolicy, interestPolicyType.getInterestPolicy());
}
}
catch (ArrayIndexOutOfBoundsException ignore) {
}
}
@Test
public void testValueOfInterestPolicyWithNull() {
assertNull(InterestPolicyType.valueOf((InterestPolicy) null));
}
@Test
public void testValueOfIgnoreCase() {
assertEquals(InterestPolicyType.ALL, InterestPolicyType.valueOfIgnoreCase("all"));
assertEquals(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.valueOfIgnoreCase("Cache_Content"));
assertEquals(InterestPolicyType.ALL, InterestPolicyType.valueOfIgnoreCase("ALL"));
assertEquals(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.valueOfIgnoreCase("CACHE_ConTent"));
}
@Test
public void testValueOfIgnoreCaseWithInvalidValues() {
assertNull(InterestPolicyType.valueOfIgnoreCase("@11"));
assertNull(InterestPolicyType.valueOfIgnoreCase("CACHE_KEYS"));
assertNull(InterestPolicyType.valueOfIgnoreCase("invalid"));
assertNull(InterestPolicyType.valueOfIgnoreCase("test"));
assertNull(InterestPolicyType.valueOfIgnoreCase(" "));
assertNull(InterestPolicyType.valueOfIgnoreCase(""));
assertNull(InterestPolicyType.valueOfIgnoreCase(null));
}
}

View File

@@ -42,48 +42,28 @@ public class SubscriptionAttributesFactoryBeanTest {
}
@Test
public void testGetObjectAndObjectTypeForSubscriptionType() throws Exception {
public void testSetAndGetInterestPolicy() {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.setType(SubscriptionType.CACHE_CONTENT);
factoryBean.afterPropertiesSet();
assertEquals(InterestPolicy.DEFAULT, factoryBean.getInterestPolicy());
assertEquals(SubscriptionType.CACHE_CONTENT, factoryBean.getType());
assertEquals(InterestPolicy.CACHE_CONTENT, factoryBean.getPolicy());
factoryBean.setInterestPolicy(InterestPolicy.CACHE_CONTENT);
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();
assertEquals(InterestPolicy.CACHE_CONTENT, factoryBean.getInterestPolicy());
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy());
assertTrue(SubscriptionAttributes.class.isAssignableFrom(factoryBean.getObjectType()));
factoryBean.setInterestPolicy(null);
assertEquals(InterestPolicy.DEFAULT, factoryBean.getInterestPolicy());
}
@Test
public void testGetObjectAndObjectTypeForDefaultSubscriptionType() throws Exception {
public void testGetObjectAndObjectTypeForAllInterestPolicy() throws Exception {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.setType(null);
factoryBean.setInterestPolicy(InterestPolicy.ALL);
factoryBean.afterPropertiesSet();
assertEquals(SubscriptionType.DEFAULT, factoryBean.getType());
assertEquals(InterestPolicy.DEFAULT, factoryBean.getPolicy());
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.DEFAULT, subscriptionAttributes.getInterestPolicy());
assertTrue(SubscriptionAttributes.class.isAssignableFrom(factoryBean.getObjectType()));
}
@Test
public void testGetObjectAndObjectTypeForInterestPolicy() throws Exception {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.setPolicy(InterestPolicy.ALL);
factoryBean.afterPropertiesSet();
assertEquals(SubscriptionType.ALL, factoryBean.getType());
assertEquals(InterestPolicy.ALL, factoryBean.getPolicy());
assertEquals(InterestPolicy.ALL, factoryBean.getInterestPolicy());
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();
@@ -92,15 +72,45 @@ public class SubscriptionAttributesFactoryBeanTest {
assertTrue(SubscriptionAttributes.class.isAssignableFrom(factoryBean.getObjectType()));
}
@Test
public void testGetObjectAndObjectTypeForCacheContentInterestPolicy() throws Exception {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.setInterestPolicy(InterestPolicy.CACHE_CONTENT);
factoryBean.afterPropertiesSet();
assertEquals(InterestPolicy.CACHE_CONTENT, factoryBean.getInterestPolicy());
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy());
assertTrue(SubscriptionAttributes.class.isAssignableFrom(factoryBean.getObjectType()));
}
@Test
public void testGetObjectAndObjectTypeForDefaultInterestPolicy() throws Exception {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.afterPropertiesSet();
assertEquals(InterestPolicy.DEFAULT, factoryBean.getInterestPolicy());
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.DEFAULT, subscriptionAttributes.getInterestPolicy());
assertTrue(SubscriptionAttributes.class.isAssignableFrom(factoryBean.getObjectType()));
}
@Test
public void testGetObjectAndObjectTypeForNullInterestPolicy() throws Exception {
SubscriptionAttributesFactoryBean factoryBean = new SubscriptionAttributesFactoryBean();
factoryBean.setPolicy(null);
factoryBean.setInterestPolicy(null);
factoryBean.afterPropertiesSet();
assertEquals(SubscriptionType.DEFAULT, factoryBean.getType());
assertEquals(InterestPolicy.DEFAULT, factoryBean.getPolicy());
assertEquals(InterestPolicy.DEFAULT, factoryBean.getInterestPolicy());
SubscriptionAttributes subscriptionAttributes = factoryBean.getObject();

View File

@@ -1,70 +0,0 @@
/*
* 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;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import com.gemstone.gemfire.cache.InterestPolicy;
/**
* The SubscriptionTypeTest class is a test suite of test cases testing the contract and functionality
* of the SubscriptionType enumerated type.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.SubscriptionType
* @since 1.6.0
*/
public class SubscriptionTypeTest {
@Test
public void testValueOfInterestPolicies() {
try {
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
InterestPolicy interestPolicy = InterestPolicy.fromOrdinal(ordinal);
SubscriptionType subscriptionType = SubscriptionType.valueOf(interestPolicy);
assertNotNull(subscriptionType);
assertEquals(interestPolicy, subscriptionType.getInterestPolicy());
}
}
catch (ArrayIndexOutOfBoundsException ignore) {
}
}
@Test
public void testValueOfIgnoreCase() {
assertEquals(SubscriptionType.ALL, SubscriptionType.valueOfIgnoreCase("all"));
assertEquals(SubscriptionType.CACHE_CONTENT, SubscriptionType.valueOfIgnoreCase("Cache_Content"));
assertEquals(SubscriptionType.DEFAULT, SubscriptionType.valueOfIgnoreCase("DeFault"));
}
@Test
public void testValueOfIgnoreCaseWithInvalidValue() {
assertNull(SubscriptionType.valueOfIgnoreCase(null));
assertNull(SubscriptionType.valueOfIgnoreCase(""));
assertNull(SubscriptionType.valueOfIgnoreCase(" "));
assertNull(SubscriptionType.valueOfIgnoreCase("@11"));
assertNull(SubscriptionType.valueOfIgnoreCase("CACHE_KEYS"));
assertNull(SubscriptionType.valueOfIgnoreCase("invalid"));
assertNull(SubscriptionType.valueOfIgnoreCase("test"));
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
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.DataPolicy;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.Region;
/**
* The RegionSubscriptionAttributesNamespaceTest class is a test suite of test cases testing the contract
* and functionality of declaring and defining Subscription Attributes for a Region in the Spring Data GemFire
* XML namespace (XSD) configuration meta-data.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.data.gemfire.SubscriptionAttributesFactoryBean
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.6.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("unused")
public class RegionSubscriptionAttributesNamespaceTest {
@Resource(name = "NoSubscriptionRegion")
private Region<?, ?> noSubscriptionRegion;
@Resource(name = "AllSubscriptionRegion")
private Region<?, ?> allSubscriptionRegion;
@Resource(name = "CacheContentSubscriptionRegion")
private Region<?, ?> cacheContentSubscriptionRegion;
@Resource(name = "DefaultSubscriptionRegion")
private Region<?, ?> defaultSubscriptionRegion;
protected void assertSubscription(final Region<?, ?> region, final String expectedRegionName,
final DataPolicy expectedDataPolicy, final InterestPolicy expectedInterestedPolicy) {
assertNotNull(String.format("The '%1$s' Region was not properly configured an initialized!",
expectedRegionName), region);
assertEquals(expectedRegionName, region.getName());
assertNotNull(region.getAttributes());
assertEquals(expectedDataPolicy, region.getAttributes().getDataPolicy());
assertNotNull(region.getAttributes().getSubscriptionAttributes());
assertEquals(expectedInterestedPolicy, region.getAttributes().getSubscriptionAttributes().getInterestPolicy());
}
@Test
public void testNoSubscriptionRegion() {
assertSubscription(noSubscriptionRegion, "NoSubscriptionRegion", DataPolicy.REPLICATE, InterestPolicy.DEFAULT);
}
@Test
public void testAllSubscriptionRegion() {
assertSubscription(allSubscriptionRegion, "AllSubscriptionRegion", DataPolicy.REPLICATE, InterestPolicy.ALL);
}
@Test
public void testCacheContentSubscriptionRegion() {
assertSubscription(cacheContentSubscriptionRegion, "CacheContentSubscriptionRegion", DataPolicy.PARTITION,
InterestPolicy.CACHE_CONTENT);
}
@Test
public void testDefaultSubscriptionRegion() {
assertSubscription(defaultSubscriptionRegion, "DefaultSubscriptionRegion", DataPolicy.PARTITION,
InterestPolicy.DEFAULT);
}
}