SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the 'evictionActionType' XSD simple-type definition and subsequently, all EvictionAction enumeration restrictions on all SDG Region element types in the SDG XML namespace (e.g. gfe:partitioned-region) that define and declare an eviction policy and corresponding 'action'. In addition, performed refactoring and cleanup on serveral new SDG enumeration types, like EvictionType and ExpirationActionType, along with the corresponding Converter implementations and bean properties on their respective FactoryBeans (EvictionAttributesFactoryBean and ExpirationAttributesFactoryBean).
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
|
||||
/**
|
||||
* The EvictionActionTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the EvictionActionTypeConverter.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see EvictionActionConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionActionConverterTest {
|
||||
|
||||
private EvictionActionConverter converter = new EvictionActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
converter.setValue(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, converter.convert("local_destroy"));
|
||||
assertEquals(EvictionAction.NONE, converter.convert("None"));
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.convert("OverFlow_TO_dIsk"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(invalid_value) is not a valid EvictionAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, converter.getValue());
|
||||
converter.setAsText("overflow_to_disk");
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destroy");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("(destroy) is not a valid EvictionAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
|
||||
/**
|
||||
* The EvictionActionTypeTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the EvictionActionType enum.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.EvictionActionType
|
||||
* @see com.gemstone.gemfire.cache.EvictionAction
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionActionTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetEvictionAction() {
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, EvictionActionType.getEvictionAction(
|
||||
EvictionActionType.LOCAL_DESTROY));
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, EvictionActionType.getEvictionAction(
|
||||
EvictionActionType.OVERFLOW_TO_DISK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticGetEvictionActionWithNull() {
|
||||
assertNull(EvictionActionType.getEvictionAction(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEvictionAction() {
|
||||
assertEquals(EvictionAction.LOCAL_DESTROY, EvictionActionType.LOCAL_DESTROY.getEvictionAction());
|
||||
assertEquals(EvictionAction.NONE, EvictionActionType.NONE.getEvictionAction());
|
||||
assertEquals(EvictionAction.OVERFLOW_TO_DISK, EvictionActionType.OVERFLOW_TO_DISK.getEvictionAction());
|
||||
assertEquals(EvictionAction.DEFAULT_EVICTION_ACTION, EvictionActionType.DEFAULT.getEvictionAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOf() {
|
||||
assertEquals(EvictionActionType.LOCAL_DESTROY, EvictionActionType.valueOf(EvictionAction.LOCAL_DESTROY));
|
||||
assertEquals(EvictionActionType.NONE, EvictionActionType.valueOf(EvictionAction.NONE));
|
||||
assertEquals(EvictionActionType.OVERFLOW_TO_DISK, EvictionActionType.valueOf(EvictionAction.OVERFLOW_TO_DISK));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithInvalidValue() {
|
||||
assertNull(EvictionActionType.valueOf((EvictionAction) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(EvictionActionType.LOCAL_DESTROY, EvictionActionType.valueOfIgnoreCase("Local_Destroy"));
|
||||
assertEquals(EvictionActionType.NONE, EvictionActionType.valueOfIgnoreCase("none"));
|
||||
assertEquals(EvictionActionType.NONE, EvictionActionType.valueOfIgnoreCase("NONE"));
|
||||
assertEquals(EvictionActionType.OVERFLOW_TO_DISK, EvictionActionType.valueOfIgnoreCase("OverFlow_TO_DiSk"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValue() {
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase("REMOTE_DESTROY"));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase("All"));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase(" none "));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase("underflow_from_disk"));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase(" "));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase(""));
|
||||
assertNull(EvictionActionType.valueOfIgnoreCase(null));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ 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 static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -59,6 +60,11 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
mockObjectSizer = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSingleton() {
|
||||
assertTrue(new EvictionAttributesFactoryBean().isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEntryCountEvictionAttributesWithNullAction() {
|
||||
factoryBean.setAction(null);
|
||||
@@ -76,23 +82,6 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEntryCountEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(mockObjectSizer);
|
||||
factoryBean.setThreshold(null);
|
||||
factoryBean.setType(EvictionType.ENTRY_COUNT);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertNull(evictionAttributes.getObjectSizer());
|
||||
assertEquals(EvictionAttributesFactoryBean.DEFAULT_LRU_MAXIMUM_ENTRIES, evictionAttributes.getMaximum());
|
||||
assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEntryCountEvictionAttributesWithLocalDestroy() {
|
||||
factoryBean.setAction(EvictionAction.LOCAL_DESTROY);
|
||||
@@ -110,6 +99,23 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEntryCountEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(mockObjectSizer);
|
||||
factoryBean.setThreshold(null);
|
||||
factoryBean.setType(EvictionType.ENTRY_COUNT);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertNull(evictionAttributes.getObjectSizer());
|
||||
assertEquals(EvictionAttributesFactoryBean.DEFAULT_LRU_MAXIMUM_ENTRIES, evictionAttributes.getMaximum());
|
||||
assertEquals(EvictionAlgorithm.LRU_ENTRY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateEntryCountEvictionAttributesWithOverflowToDisk() {
|
||||
factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK);
|
||||
@@ -142,22 +148,6 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHeapPercentageEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(mockObjectSizer);
|
||||
factoryBean.setThreshold(null);
|
||||
factoryBean.setType(EvictionType.HEAP_PERCENTAGE);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertSame(mockObjectSizer, evictionAttributes.getObjectSizer());
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHeapPercentageEvictionAttributesWithLocalDestroy() {
|
||||
factoryBean.setAction(EvictionAction.LOCAL_DESTROY);
|
||||
@@ -174,6 +164,22 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHeapPercentageEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(mockObjectSizer);
|
||||
factoryBean.setThreshold(null);
|
||||
factoryBean.setType(EvictionType.HEAP_PERCENTAGE);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertSame(mockObjectSizer, evictionAttributes.getObjectSizer());
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateHeapPercentageEvictionAttributesWithOverflowToDisk() {
|
||||
factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK);
|
||||
@@ -200,7 +206,7 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
factoryBean.afterPropertiesSet();
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("The HEAP_PERCENTAGE (LRU_HEAP algorithm) does not support threshold (a.k.a. maximum)!",
|
||||
assertEquals("HEAP_PERCENTAGE (LRU_HEAP algorithm) does not support threshold (a.k.a. maximum)!",
|
||||
expected.getMessage());
|
||||
assertEquals(85, factoryBean.getThreshold().intValue());
|
||||
assertEquals(EvictionType.HEAP_PERCENTAGE, factoryBean.getType());
|
||||
@@ -225,23 +231,6 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMemorySizeEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(null);
|
||||
factoryBean.setThreshold(256);
|
||||
factoryBean.setType(EvictionType.MEMORY_SIZE);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertNull(evictionAttributes.getObjectSizer());
|
||||
assertEquals(256, evictionAttributes.getMaximum());
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMemorySizeEvictionAttributesWithLocalDestroy() {
|
||||
factoryBean.setAction(EvictionAction.LOCAL_DESTROY);
|
||||
@@ -259,6 +248,23 @@ public class EvictionAttributesFactoryBeanTest {
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMemorySizeEvictionAttributesWithNone() {
|
||||
factoryBean.setAction(EvictionAction.NONE);
|
||||
factoryBean.setObjectSizer(null);
|
||||
factoryBean.setThreshold(256);
|
||||
factoryBean.setType(EvictionType.MEMORY_SIZE);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
EvictionAttributes evictionAttributes = factoryBean.getObject();
|
||||
|
||||
assertNotNull(evictionAttributes);
|
||||
assertEquals(EvictionAction.NONE, evictionAttributes.getAction());
|
||||
assertNull(evictionAttributes.getObjectSizer());
|
||||
assertEquals(256, evictionAttributes.getMaximum());
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, evictionAttributes.getAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateMemorySizeEvictionAttributesWithOverflowToDisk() {
|
||||
factoryBean.setAction(EvictionAction.OVERFLOW_TO_DISK);
|
||||
|
||||
@@ -49,12 +49,12 @@ public class EvictionTypeConverterTest {
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertWithIllegalValue() {
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("LIFO_MEMORY");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Source (LIFO_MEMORY) is not a valid EvictionType!", expected.getMessage());
|
||||
assertEquals("(LIFO_MEMORY) is not a valid EvictionType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,16 @@ public class EvictionTypeConverterTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextWithIllegalValue() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("LRU_COUNT");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Source (LRU_COUNT) is not a valid EvictionType!", expected.getMessage());
|
||||
assertEquals("(LRU_COUNT) is not a valid EvictionType!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,17 +30,41 @@ import com.gemstone.gemfire.cache.EvictionAlgorithm;
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.EvictionType
|
||||
* @see com.gemstone.gemfire.cache.EvictionAlgorithm
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class EvictionTypeTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testStaticGetEvictionAlgorithm() {
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionType.getEvictionAlgorithm(EvictionType.HEAP_PERCENTAGE));
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionType.getEvictionAlgorithm(EvictionType.MEMORY_SIZE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticGetEvictionAlgorithmWithNull() {
|
||||
assertNull(EvictionType.getEvictionAlgorithm(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEvictionAlgorithm() {
|
||||
assertEquals(EvictionAlgorithm.LRU_ENTRY, EvictionType.ENTRY_COUNT.getEvictionAlgorithm());
|
||||
assertEquals(EvictionAlgorithm.LRU_HEAP, EvictionType.HEAP_PERCENTAGE.getEvictionAlgorithm());
|
||||
assertEquals(EvictionAlgorithm.LRU_MEMORY, EvictionType.MEMORY_SIZE.getEvictionAlgorithm());
|
||||
assertEquals(EvictionAlgorithm.NONE, EvictionType.NONE.getEvictionAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfEvictionAlgorithms() {
|
||||
assertEquals(EvictionType.ENTRY_COUNT, EvictionType.valueOf(EvictionAlgorithm.LRU_ENTRY));
|
||||
assertEquals(EvictionType.HEAP_PERCENTAGE, EvictionType.valueOf(EvictionAlgorithm.LRU_HEAP));
|
||||
assertEquals(EvictionType.MEMORY_SIZE, EvictionType.valueOf(EvictionAlgorithm.LRU_MEMORY));
|
||||
assertEquals(EvictionType.NONE, EvictionType.valueOf(EvictionAlgorithm.NONE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testValueOfInvalidEvictionAlgorithms() {
|
||||
assertNull(EvictionType.valueOf(EvictionAlgorithm.LIFO_ENTRY));
|
||||
assertNull(EvictionType.valueOf(EvictionAlgorithm.LIFO_MEMORY));
|
||||
assertNull(EvictionType.valueOf((EvictionAlgorithm) null));
|
||||
@@ -56,6 +80,7 @@ public class EvictionTypeTest {
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(EvictionType.valueOfIgnoreCase("number_of_entries"));
|
||||
assertNull(EvictionType.valueOfIgnoreCase("heap_%"));
|
||||
assertNull(EvictionType.valueOfIgnoreCase("mem_size"));
|
||||
assertNull(EvictionType.valueOfIgnoreCase("memory_space"));
|
||||
|
||||
@@ -17,22 +17,25 @@
|
||||
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.ExpirationAction;
|
||||
|
||||
/**
|
||||
* The ExpirationActionTypeConverterTest class is a test suite of test cases testing the contract and functionality
|
||||
* of the ExpirationActionTypeConverter class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.ExpirationActionTypeConverter
|
||||
* @see ExpirationActionConverter
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ExpirationActionTypeConverterTest {
|
||||
public class ExpirationActionConverterTest {
|
||||
|
||||
private final ExpirationActionTypeConverter converter = new ExpirationActionTypeConverter();
|
||||
private final ExpirationActionConverter converter = new ExpirationActionConverter();
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
@@ -41,19 +44,19 @@ public class ExpirationActionTypeConverterTest {
|
||||
|
||||
@Test
|
||||
public void testConvert() {
|
||||
assertEquals(ExpirationActionType.DESTROY, converter.convert("destroy"));
|
||||
assertEquals(ExpirationActionType.INVALIDATE, converter.convert("InvalidAte"));
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, converter.convert("LOCAL_dEsTrOy"));
|
||||
assertEquals(ExpirationActionType.LOCAL_INVALIDATE, converter.convert("Local_Invalidate"));
|
||||
assertEquals(ExpirationAction.DESTROY, converter.convert("destroy"));
|
||||
assertEquals(ExpirationAction.INVALIDATE, converter.convert("inValidAte"));
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, converter.convert("LOCAL_dEsTrOy"));
|
||||
assertEquals(ExpirationAction.LOCAL_INVALIDATE, converter.convert("Local_Invalidate"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testConvertThrowsIllegalArgumentException() {
|
||||
public void testConvertIllegalValue() {
|
||||
try {
|
||||
converter.convert("blow_up");
|
||||
converter.convert("invalid_value");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Source (blow_up) is not a valid ExpirationActionType!", expected.getMessage());
|
||||
assertEquals("(invalid_value) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
}
|
||||
@@ -61,20 +64,24 @@ public class ExpirationActionTypeConverterTest {
|
||||
@Test
|
||||
public void testSetAsText() {
|
||||
converter.setAsText("InValidAte");
|
||||
assertEquals(ExpirationActionType.INVALIDATE, converter.getValue());
|
||||
assertEquals(ExpirationAction.INVALIDATE, converter.getValue());
|
||||
converter.setAsText("Local_Destroy");
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, converter.getValue());
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, converter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetAsTextThrowsIllegalArgumentException() {
|
||||
try {
|
||||
assertNull(converter.getValue());
|
||||
converter.setAsText("destruction");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
assertEquals("Source (destruction) is not a valid ExpirationActionType!", expected.getMessage());
|
||||
assertEquals("(destruction) is not a valid ExpirationAction!", expected.getMessage());
|
||||
throw expected;
|
||||
}
|
||||
finally {
|
||||
assertNull(converter.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
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;
|
||||
@@ -31,10 +30,31 @@ import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.springframework.data.gemfire.ExpirationActionType
|
||||
* @see com.gemstone.gemfire.cache.ExpirationAction
|
||||
* @since 1.6.0
|
||||
*/
|
||||
public class ExpirationActionTypeTest {
|
||||
|
||||
@Test
|
||||
public void testStaticGetExpirationAction() {
|
||||
assertEquals(ExpirationAction.DESTROY, ExpirationActionType.getExpirationAction(ExpirationActionType.DESTROY));
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, ExpirationActionType.getExpirationAction(
|
||||
ExpirationActionType.LOCAL_DESTROY));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStaticGetExpirationActionWithNull() {
|
||||
assertNull(ExpirationActionType.getExpirationAction(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetExpirationAction() {
|
||||
assertEquals(ExpirationAction.DESTROY, ExpirationActionType.DESTROY.getExpirationAction());
|
||||
assertEquals(ExpirationAction.INVALIDATE, ExpirationActionType.INVALIDATE.getExpirationAction());
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, ExpirationActionType.LOCAL_DESTROY.getExpirationAction());
|
||||
assertEquals(ExpirationAction.LOCAL_INVALIDATE, ExpirationActionType.LOCAL_INVALIDATE.getExpirationAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
assertEquals(ExpirationActionType.INVALIDATE, ExpirationActionType.DEFAULT);
|
||||
@@ -54,13 +74,19 @@ public class ExpirationActionTypeTest {
|
||||
public void testValueOfExpirationActionOrdinalValues() {
|
||||
try {
|
||||
for (int ordinal = 0; ordinal < Integer.MAX_VALUE; ordinal++) {
|
||||
assertNotNull(ExpirationActionType.valueOf(ExpirationAction.fromOrdinal(ordinal)));
|
||||
ExpirationAction expirationAction = ExpirationAction.fromOrdinal(ordinal);
|
||||
assertEquals(expirationAction, ExpirationActionType.valueOf(expirationAction).getExpirationAction());
|
||||
}
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfWithNull() {
|
||||
assertNull(ExpirationActionType.valueOf((ExpirationAction) null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCase() {
|
||||
assertEquals(ExpirationActionType.DESTROY, ExpirationActionType.valueOfIgnoreCase("destroy"));
|
||||
@@ -70,9 +96,12 @@ public class ExpirationActionTypeTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValueOfIgnoreCaseWithInvalidStringValues() {
|
||||
public void testValueOfIgnoreCaseWithInvalidValues() {
|
||||
assertNull(ExpirationActionType.valueOfIgnoreCase("Invalid"));
|
||||
assertNull(ExpirationActionType.valueOfIgnoreCase("local destroy"));
|
||||
assertNull(ExpirationActionType.valueOfIgnoreCase(" "));
|
||||
assertNull(ExpirationActionType.valueOfIgnoreCase(""));
|
||||
assertNull(ExpirationActionType.valueOfIgnoreCase(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public class ExpirationAttributesFactoryBeanTest {
|
||||
assertEquals(ExpirationAttributesFactoryBean.DEFAULT_EXPIRATION_ACTION,
|
||||
expirationAttributesFactoryBean.getAction());
|
||||
|
||||
expirationAttributesFactoryBean.setAction(ExpirationActionType.LOCAL_DESTROY);
|
||||
expirationAttributesFactoryBean.setAction(ExpirationAction.LOCAL_DESTROY);
|
||||
|
||||
assertEquals(ExpirationActionType.LOCAL_DESTROY, expirationAttributesFactoryBean.getAction());
|
||||
assertEquals(ExpirationAction.LOCAL_DESTROY, expirationAttributesFactoryBean.getAction());
|
||||
|
||||
expirationAttributesFactoryBean.setAction(null);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ExpirationAttributesFactoryBeanTest {
|
||||
assertNull(expirationAttributesFactoryBean.getObject());
|
||||
assertEquals(ExpirationAttributes.class, expirationAttributesFactoryBean.getObjectType());
|
||||
|
||||
expirationAttributesFactoryBean.setAction(ExpirationActionType.DESTROY);
|
||||
expirationAttributesFactoryBean.setAction(ExpirationAction.DESTROY);
|
||||
expirationAttributesFactoryBean.setTimeout(8192);
|
||||
expirationAttributesFactoryBean.afterPropertiesSet();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user