SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the XSD enumeration restriction on the 'result-policy' attribute of the 'interestType' SDG XSD complex-type definition in order to allow users to specify an Interest Policy using concrete values or properly placeholders when registering client Region Interests.
This commit is contained in:
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -56,6 +57,12 @@ public class EvictionActionTypeTest {
|
||||
assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, EvictionActionType.DEFAULT.getEvictionAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, EvictionActionType.DEFAULT.getEvictionAction());
|
||||
assertSame(EvictionActionType.LOCAL_DESTROY, EvictionActionType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
assertEquals(EvictionActionType.LOCAL_DESTROY, EvictionActionType.valueOf(EvictionAction.LOCAL_DESTROY));
|
||||
|
||||
@@ -37,10 +37,10 @@ public class EvictionPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetEvictionAlgorithm() {
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionPolicyType
|
||||
.getEvictionAlgorithm(EvictionPolicyType.HEAP_PERCENTAGE));
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionPolicyType
|
||||
.getEvictionAlgorithm(EvictionPolicyType.MEMORY_SIZE));
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionPolicyType.getEvictionAlgorithm(
|
||||
EvictionPolicyType.HEAP_PERCENTAGE));
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionPolicyType.getEvictionAlgorithm(
|
||||
EvictionPolicyType.MEMORY_SIZE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +57,7 @@ public class EvictionPolicyTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfEvictionAlgorithms() {
|
||||
public void testValueOf() {
|
||||
assertEquals(EvictionPolicyType.ENTRY_COUNT, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_ENTRY));
|
||||
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_HEAP));
|
||||
assertEquals(EvictionPolicyType.MEMORY_SIZE, EvictionPolicyType.valueOf(EvictionAlgorithm.LRU_MEMORY));
|
||||
@@ -69,6 +69,10 @@ public class EvictionPolicyTypeTest {
|
||||
public void testValueOfInvalidEvictionAlgorithms() {
|
||||
assertNull(EvictionPolicyType.valueOf(EvictionAlgorithm.LIFO_ENTRY));
|
||||
assertNull(EvictionPolicyType.valueOf(EvictionAlgorithm.LIFO_MEMORY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(EvictionPolicyType.valueOf((EvictionAlgorithm) null));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,10 +53,10 @@ public class ExpirationActionConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid_value");
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
assertEquals("(illegal_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class ExpirationActionConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextThrowsIllegalArgumentException() {
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destruction");
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -58,7 +60,7 @@ public class ExpirationActionTypeTest {
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(ExpirationAction.INVALIDATE, ExpirationActionType.DEFAULT.getExpirationAction());
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
|
||||
assertSame(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +69,6 @@ public class ExpirationActionTypeTest {
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.valueOf(ExpirationAction.INVALIDATE));
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, ExpirationActionType.valueOf(ExpirationAction.LOCAL_DESTROY));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOf(ExpirationAction.LOCAL_INVALIDATE));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,7 +76,10 @@ public class ExpirationActionTypeTest {
|
||||
try {
|
||||
for (int ordinal = 0; ordinal < Integer.MAX_VALUE; ordinal++) {
|
||||
ExpirationAction expirationAction = ExpirationAction.fromOrdinal(ordinal);
|
||||
assertEquals(expirationAction, ExpirationActionType.valueOf(expirationAction).getExpirationAction());
|
||||
ExpirationActionType expirationActionType = ExpirationActionType.valueOf(expirationAction);
|
||||
|
||||
assertNotNull(expirationActionType);
|
||||
assertEquals(expirationAction, expirationActionType.getExpirationAction());
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException ignore) {
|
||||
@@ -92,7 +96,7 @@ public class ExpirationActionTypeTest {
|
||||
assertEquals(ExpirationActionType.DESTROY, ExpirationActionType.valueOfIgnoreCase("destroy"));
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.valueOfIgnoreCase("Invalidate"));
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, ExpirationActionType.valueOfIgnoreCase("LOCAL_DESTROY"));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOfIgnoreCase("Local_Invalidate"));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, ExpirationActionType.valueOfIgnoreCase("LocaL_InValidAte"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -67,7 +67,7 @@ public class IndexMaintenancePolicyConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextThrowsIllegalArgumentException() {
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("async");
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.gemfire;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -41,7 +42,7 @@ public class IndexMaintenancePolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, IndexMaintenancePolicyType.DEFAULT);
|
||||
assertSame(IndexMaintenancePolicyType.SYNCHRONOUS, IndexMaintenancePolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -50,7 +50,7 @@ public class IndexTypeConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertWithInvalidValue() {
|
||||
public void testConvertWithIllegalValue() {
|
||||
try {
|
||||
converter.convert("function");
|
||||
}
|
||||
@@ -72,12 +72,16 @@ public class IndexTypeConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("invalid");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Failed to convert String (invalid) into an IndexType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.junit.Test;
|
||||
public class IndexTypeTest {
|
||||
|
||||
@Test
|
||||
public void testGetGemFireIndexType() {
|
||||
public void testGetGemfireIndexType() {
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL, IndexType.FUNCTIONAL.getGemfireIndexType());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.HASH, IndexType.HASH.getGemfireIndexType());
|
||||
assertEquals(com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY, IndexType.KEY.getGemfireIndexType());
|
||||
@@ -44,13 +44,17 @@ public class IndexTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfGemFireIndexType() {
|
||||
assertNull(IndexType.valueOf((com.gemstone.gemfire.cache.query.IndexType) null));
|
||||
public void testValueOf() {
|
||||
assertEquals(IndexType.FUNCTIONAL, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.FUNCTIONAL));
|
||||
assertEquals(IndexType.HASH, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.HASH));
|
||||
assertEquals(IndexType.PRIMARY_KEY, IndexType.valueOf(com.gemstone.gemfire.cache.query.IndexType.PRIMARY_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(IndexType.valueOf((com.gemstone.gemfire.cache.query.IndexType) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(IndexType.FUNCTIONAL, IndexType.valueOfIgnoreCase("functional"));
|
||||
@@ -61,12 +65,12 @@ public class IndexTypeTest {
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(IndexType.valueOfIgnoreCase(null));
|
||||
assertNull(IndexType.valueOfIgnoreCase(""));
|
||||
assertNull(IndexType.valueOfIgnoreCase(" "));
|
||||
assertNull(IndexType.valueOfIgnoreCase("Prime_Index"));
|
||||
assertNull(IndexType.valueOfIgnoreCase("SECONDARY_INDEX"));
|
||||
assertNull(IndexType.valueOfIgnoreCase("unique_index"));
|
||||
assertNull(IndexType.valueOfIgnoreCase(null));
|
||||
assertNull(IndexType.valueOfIgnoreCase(" "));
|
||||
assertNull(IndexType.valueOfIgnoreCase(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -52,12 +52,12 @@ public class InterestPolicyConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValueValue() {
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid");
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid) is not a valid InterestPolicy!", expected.getMessage());
|
||||
assertEquals("(invalid_value) is not a valid InterestPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.data.gemfire;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -55,16 +56,17 @@ public class InterestPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(InterestPolicy.DEFAULT, InterestPolicyType.valueOf(InterestPolicy.DEFAULT).getInterestPolicy());
|
||||
assertEquals(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.DEFAULT);
|
||||
assertEquals(InterestPolicy.DEFAULT, InterestPolicyType.DEFAULT.getInterestPolicy());
|
||||
assertSame(InterestPolicyType.CACHE_CONTENT, InterestPolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfInterestPolicies() {
|
||||
public void testValueOf() {
|
||||
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());
|
||||
}
|
||||
@@ -74,7 +76,7 @@ public class InterestPolicyTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfInterestPolicyWithNull() {
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(InterestPolicyType.valueOf((InterestPolicy) null));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
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.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestResultPolicyConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyConverter
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyType
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyConverterTest {
|
||||
|
||||
private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("NONE"));
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.convert("Keys"));
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, converter.convert("kEyS_ValUes"));
|
||||
assertEquals(InterestResultPolicy.NONE, converter.convert("nONe"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("NOne");
|
||||
assertEquals(InterestResultPolicy.NONE, converter.getValue());
|
||||
converter.setAsText("KeYs");
|
||||
assertEquals(InterestResultPolicy.KEYS, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("illegal_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(illegal_value) is not a valid InterestResultPolicy!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestResultPolicyTypeTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the InterestResultPolicyType enum.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.InterestResultPolicyTypeTest
|
||||
* @see com.gemstone.gemfire.cache.InterestResultPolicy
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestResultPolicyTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetInterestResultPolicy() {
|
||||
assertEquals(InterestResultPolicy.KEYS, InterestResultPolicyType.getInterestResultPolicy(
|
||||
InterestResultPolicyType.KEYS));
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, InterestResultPolicyType.getInterestResultPolicy(
|
||||
InterestResultPolicyType.KEYS_VALUES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticGetInterestResultPolicyWithNull() {
|
||||
assertNull(InterestResultPolicyType.getInterestResultPolicy(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(InterestResultPolicyType.DEFAULT, InterestResultPolicyType.valueOf(InterestResultPolicy.DEFAULT));
|
||||
assertEquals(InterestResultPolicy.DEFAULT, InterestResultPolicyType.DEFAULT.getInterestResultPolicy());
|
||||
assertSame(InterestResultPolicyType.KEYS_VALUES, InterestResultPolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
try {
|
||||
for (byte ordinal = 0; ordinal < Byte.MAX_VALUE; ordinal++) {
|
||||
InterestResultPolicy interestResultPolicy = InterestResultPolicy.fromOrdinal(ordinal);
|
||||
InterestResultPolicyType interestResultPolicyType = InterestResultPolicyType.valueOf(
|
||||
interestResultPolicy);
|
||||
|
||||
assertNotNull(interestResultPolicyType);
|
||||
assertEquals(interestResultPolicy, interestResultPolicyType.getInterestResultPolicy());
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(InterestResultPolicyType.valueOf((InterestResultPolicy) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(InterestResultPolicyType.KEYS, InterestResultPolicyType.valueOfIgnoreCase("KEYS"));
|
||||
assertEquals(InterestResultPolicyType.KEYS_VALUES, InterestResultPolicyType.valueOfIgnoreCase("Keys_Values"));
|
||||
assertEquals(InterestResultPolicyType.NONE, InterestResultPolicyType.valueOfIgnoreCase("none"));
|
||||
assertEquals(InterestResultPolicyType.NONE, InterestResultPolicyType.valueOfIgnoreCase("nONE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("keyz"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("KEY_VALUE"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase("all"));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(" "));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(""));
|
||||
assertNull(InterestResultPolicyType.valueOfIgnoreCase(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.ConstantException;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
|
||||
/**
|
||||
* The InterestTest class is a test suite of test cases testing the contract and functionality of the Interest class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.client.Interest
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class InterestTest {
|
||||
|
||||
@Test
|
||||
public void testConstruct() {
|
||||
Interest<String> interest = new Interest<String>("aKey", "keys", true, false);
|
||||
|
||||
assertEquals("aKey", interest.getKey());
|
||||
assertEquals(InterestResultPolicy.KEYS, interest.getPolicy());
|
||||
assertTrue(interest.isDurable());
|
||||
assertFalse(interest.isReceiveValues());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConstructWithNullKey() {
|
||||
try {
|
||||
new Interest<Object>(null);
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("a non-null key is required", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = ConstantException.class)
|
||||
public void testConstructWithInvalidPolicy() {
|
||||
new Interest<String>("aKey", "INVALID");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetState() {
|
||||
Interest<String> interest = new Interest();
|
||||
|
||||
assertNull(interest.getKey());
|
||||
assertEquals(InterestResultPolicy.DEFAULT, interest.getPolicy());
|
||||
assertFalse(interest.isDurable());
|
||||
assertTrue(interest.isReceiveValues());
|
||||
|
||||
interest.setDurable(true);
|
||||
interest.setKey("testKey");
|
||||
interest.setPolicy(InterestResultPolicy.KEYS_VALUES);
|
||||
interest.setReceiveValues(false);
|
||||
|
||||
assertEquals("testKey", interest.getKey());
|
||||
assertEquals(InterestResultPolicy.KEYS_VALUES, interest.getPolicy());
|
||||
assertTrue(interest.isDurable());
|
||||
assertFalse(interest.isReceiveValues());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetPolicy() {
|
||||
Interest<Object> interest = new Interest<Object>();
|
||||
|
||||
assertEquals(InterestResultPolicy.DEFAULT, interest.getPolicy());
|
||||
|
||||
interest.setPolicy(InterestResultPolicy.NONE);
|
||||
|
||||
assertEquals(InterestResultPolicy.NONE, interest.getPolicy());
|
||||
|
||||
interest.setPolicy("keys");
|
||||
|
||||
assertEquals(InterestResultPolicy.KEYS, interest.getPolicy());
|
||||
}
|
||||
|
||||
@Test(expected = ConstantException.class)
|
||||
public void testSetPolicyWithIllegalValue() {
|
||||
new Interest<Object>().setPolicy("ILLEGAL");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,19 +22,29 @@ import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
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 static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.SimpleCacheListener;
|
||||
import org.springframework.data.gemfire.SimpleObjectSizer;
|
||||
import org.springframework.data.gemfire.TestUtils;
|
||||
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
|
||||
import org.springframework.data.gemfire.client.Interest;
|
||||
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -48,9 +58,11 @@ import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.EvictionAlgorithm;
|
||||
import com.gemstone.gemfire.cache.EvictionAttributes;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.LoaderHelper;
|
||||
import com.gemstone.gemfire.cache.Region;
|
||||
import com.gemstone.gemfire.cache.RegionAttributes;
|
||||
import com.gemstone.gemfire.cache.client.ClientCache;
|
||||
import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
|
||||
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
|
||||
import com.gemstone.gemfire.compression.Compressor;
|
||||
@@ -245,6 +257,85 @@ public class ClientRegionNamespaceTest {
|
||||
assertEquals(String.class, clientRegion.getAttributes().getValueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testClientRegionWithRegisteredInterests() throws Exception {
|
||||
assertTrue(context.containsBean("client-with-interests"));
|
||||
|
||||
ClientRegionFactoryBean factory = context.getBean("&client-with-interests", ClientRegionFactoryBean.class);
|
||||
|
||||
assertNotNull(factory);
|
||||
|
||||
Interest<?>[] interests = TestUtils.readField("interests", factory);
|
||||
|
||||
assertNotNull(interests);
|
||||
assertEquals(2, interests.length);
|
||||
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS, getInterestWithKey(".*", interests));
|
||||
assertInterest(true, false, InterestResultPolicy.KEYS_VALUES, getInterestWithKey("keyPrefix.*", interests));
|
||||
|
||||
Region mockClientRegion = MockCacheFactoryBean.MOCK_REGION_REF.get();
|
||||
|
||||
assertNotNull(mockClientRegion);
|
||||
|
||||
verify(mockClientRegion, times(1)).registerInterest(eq(".*"), eq(InterestResultPolicy.KEYS),
|
||||
eq(true), eq(false));
|
||||
verify(mockClientRegion, times(1)).registerInterestRegex(eq("keyPrefix.*"), eq(InterestResultPolicy.KEYS_VALUES),
|
||||
eq(true), eq(false));
|
||||
}
|
||||
|
||||
protected void assertInterest(final boolean expectedDurable, final boolean expectedReceiveValues,
|
||||
final InterestResultPolicy expectedPolicy, final Interest actualInterest) {
|
||||
assertNotNull(actualInterest);
|
||||
assertEquals(expectedDurable, actualInterest.isDurable());
|
||||
assertEquals(expectedReceiveValues, actualInterest.isReceiveValues());
|
||||
assertEquals(expectedPolicy, actualInterest.getPolicy());
|
||||
}
|
||||
|
||||
protected Interest getInterestWithKey(final String key, final Interest... interests) {
|
||||
for (Interest interest : interests) {
|
||||
if (interest.getKey().equals(key)) {
|
||||
return interest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class MockCacheFactoryBean implements FactoryBean<ClientCache>, InitializingBean {
|
||||
|
||||
protected static final AtomicReference<Region> MOCK_REGION_REF = new AtomicReference<Region>(null);
|
||||
|
||||
private ClientCache mockClientCache;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
mockClientCache = mock(ClientCache.class, ClientRegionNamespaceTest.class.getSimpleName()
|
||||
.concat(".MockClientCache"));
|
||||
|
||||
MOCK_REGION_REF.compareAndSet(null, mock(Region.class, ClientRegionNamespaceTest.class.getSimpleName()
|
||||
.concat(".MockClientRegion")));
|
||||
|
||||
when(mockClientCache.getRegion(anyString())).thenReturn(MOCK_REGION_REF.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientCache getObject() throws Exception {
|
||||
return mockClientCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return ClientCache.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class TestCacheLoader implements CacheLoader<Object, Object> {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -30,9 +30,6 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
this.useBeanFactoryLocator = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bean
|
||||
*/
|
||||
public MockCacheFactoryBean(CacheFactoryBean cacheFactoryBean) {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
@@ -70,8 +67,9 @@ public class MockCacheFactoryBean extends CacheFactoryBean {
|
||||
return new CacheFactory(gemfireProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GemFireCache fetchCache() {
|
||||
((StubCache) cache).setProperties(this.properties);
|
||||
((StubCache) cache).setProperties(getProperties());
|
||||
return cache;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
this();
|
||||
if (cacheFactoryBean != null) {
|
||||
this.factoryLocator = cacheFactoryBean.getBeanFactoryLocator();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.beanFactory = cacheFactoryBean.getBeanFactory();
|
||||
this.beanName = cacheFactoryBean.getBeanName();
|
||||
this.beanClassLoader = cacheFactoryBean.getBeanClassLoader();
|
||||
this.cacheXml = cacheFactoryBean.getCacheXml();
|
||||
this.copyOnRead = cacheFactoryBean.getCopyOnRead();
|
||||
this.criticalHeapPercentage = cacheFactoryBean.getCriticalHeapPercentage();
|
||||
@@ -54,16 +54,17 @@ public class MockClientCacheFactoryBean extends ClientCacheFactoryBean {
|
||||
this.pdxPersistent = cacheFactoryBean.getPdxPersistent();
|
||||
this.pdxSerializer = cacheFactoryBean.getPdxSerializer();
|
||||
this.properties = cacheFactoryBean.getProperties();
|
||||
this.readyForEvents = cacheFactoryBean.getReadyForEvents();
|
||||
this.searchTimeout = cacheFactoryBean.getSearchTimeout();
|
||||
this.transactionListeners = cacheFactoryBean.getTransactionListeners();
|
||||
this.transactionWriter = cacheFactoryBean.getTransactionWriter();
|
||||
this.readyForEvents = cacheFactoryBean.getReadyForEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object createFactory(Properties gemfireProperties) {
|
||||
((StubCache)cache).setProperties(gemfireProperties);
|
||||
setProperties(gemfireProperties);
|
||||
return new ClientCacheFactory(gemfireProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user