SGF-538 - Reorganize the XML configuration classes and support in SDG.

(cherry picked from commit d914f7427483d3e583aea13f061f3cdc20be84f8)
Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
John Blum
2016-09-30 19:38:41 -07:00
parent fba37379cd
commit f64765ef70
185 changed files with 3685 additions and 2754 deletions

View File

@@ -27,7 +27,7 @@ import org.junit.After;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import com.gemstone.gemfire.cache.Cache;

View File

@@ -1,87 +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.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());
}
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.EvictionAction;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link EvictionActionConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.EvictionActionConverter
* @see com.gemstone.gemfire.cache.EvictionAction
* @since 1.6.0
*/
public class EvictionActionConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private EvictionActionConverter converter = new EvictionActionConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("local_destroy")).isEqualTo(EvictionAction.LOCAL_DESTROY);
assertThat(converter.convert("None")).isEqualTo(EvictionAction.NONE);
assertThat(converter.convert("OverFlow_TO_dIsk")).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[invalid_value] is not a valid EvictionAction");
converter.convert("invalid_value");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("Local_Destroy");
assertThat(converter.getValue()).isEqualTo(EvictionAction.LOCAL_DESTROY);
converter.setAsText("overflow_to_disk");
assertThat(converter.getValue()).isEqualTo(EvictionAction.OVERFLOW_TO_DISK);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[destroy] is not a valid EvictionAction");
converter.setAsText("destroy");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,87 +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.assertNull;
import org.junit.After;
import org.junit.Test;
/**
* The EvictionTypeConverterTest class is a test suite of test cases testing the contract and functionality
* of the EvictionTypeConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.EvictionPolicyConverter
* @see org.springframework.data.gemfire.EvictionPolicyType
* @since 1.6.0
*/
public class EvictionPolicyConverterTest {
private final EvictionPolicyConverter converter = new EvictionPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(EvictionPolicyType.ENTRY_COUNT, converter.convert("entry_count"));
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.convert("Heap_Percentage"));
assertEquals(EvictionPolicyType.MEMORY_SIZE, converter.convert("MEMorY_SiZe"));
assertEquals(EvictionPolicyType.NONE, converter.convert("NONE"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.convert("LIFO_MEMORY");
}
catch (IllegalArgumentException expected) {
assertEquals("(LIFO_MEMORY) is not a valid EvictionPolicyType!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
assertNull(converter.getValue());
converter.setAsText("heap_percentage");
assertEquals(EvictionPolicyType.HEAP_PERCENTAGE, converter.getValue());
converter.setAsText("NOne");
assertEquals(EvictionPolicyType.NONE, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("LRU_COUNT");
}
catch (IllegalArgumentException expected) {
assertEquals("(LRU_COUNT) is not a valid EvictionPolicyType!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,88 @@
/*
* 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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link EvictionPolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.EvictionPolicyConverter
* @see org.springframework.data.gemfire.EvictionPolicyType
* @since 1.6.0
*/
public class EvictionPolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final EvictionPolicyConverter converter = new EvictionPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("entry_count")).isEqualTo(EvictionPolicyType.ENTRY_COUNT);
assertThat(converter.convert("Heap_Percentage")).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE);
assertThat(converter.convert("MEMorY_SiZe")).isEqualTo(EvictionPolicyType.MEMORY_SIZE);
assertThat(converter.convert("NONE")).isEqualTo(EvictionPolicyType.NONE);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[LIFO_MEMORY] is not a valid EvictionPolicyType");
converter.convert("LIFO_MEMORY");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("heap_percentage");
assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.HEAP_PERCENTAGE);
converter.setAsText("NOne");
assertThat(converter.getValue()).isEqualTo(EvictionPolicyType.NONE);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[LRU_COUNT] is not a valid EvictionPolicyType");
converter.setAsText("LRU_COUNT");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,87 +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.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 ExpirationActionConverter
* @since 1.6.0
*/
public class ExpirationActionConverterTest {
private final ExpirationActionConverter converter = new ExpirationActionConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
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 testConvertIllegalValue() {
try {
converter.convert("illegal_value");
}
catch (IllegalArgumentException expected) {
assertEquals("(illegal_value) is not a valid ExpirationAction!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
converter.setAsText("InValidAte");
assertEquals(ExpirationAction.INVALIDATE, converter.getValue());
converter.setAsText("Local_Destroy");
assertEquals(ExpirationAction.LOCAL_DESTROY, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("destruction");
}
catch (IllegalArgumentException expected) {
assertEquals("(destruction) is not a valid ExpirationAction!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.ExpirationAction;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link ExpirationActionConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.ExpirationActionConverter
* @since 1.6.0
*/
public class ExpirationActionConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final ExpirationActionConverter converter = new ExpirationActionConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("destroy")).isEqualTo(ExpirationAction.DESTROY);
assertThat(converter.convert("inValidAte")).isEqualTo(ExpirationAction.INVALIDATE);
assertThat(converter.convert("LOCAL_dEsTrOy")).isEqualTo(ExpirationAction.LOCAL_DESTROY);
assertThat(converter.convert("Local_Invalidate")).isEqualTo(ExpirationAction.LOCAL_INVALIDATE);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[illegal_value] is not a valid ExpirationAction");
converter.convert("illegal_value");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("InValidAte");
assertThat(converter.getValue()).isEqualTo(ExpirationAction.INVALIDATE);
converter.setAsText("Local_Destroy");
assertThat(converter.getValue()).isEqualTo(ExpirationAction.LOCAL_DESTROY);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[destruction] is not a valid ExpirationAction");
converter.setAsText("destruction");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -57,7 +57,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.util.ReflectionUtils;
import com.gemstone.gemfire.cache.Cache;

View File

@@ -1,84 +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.assertNull;
import org.junit.After;
import org.junit.Test;
/**
* The IndexMaintenanceTypeConverterTest class is a test suite of test case testing the contract and functionality
* of the IndexMaintenancePolicyConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter
* @see org.springframework.data.gemfire.IndexMaintenancePolicyType
* @since 1.6.0
*/
public class IndexMaintenancePolicyConverterTest {
private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.convert("asynchronous"));
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.convert("Synchronous"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.convert("sync");
}
catch (IllegalArgumentException expected) {
assertEquals("(sync) is not a valid IndexMaintenancePolicyType!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
converter.setAsText("aSynchronous");
assertEquals(IndexMaintenancePolicyType.ASYNCHRONOUS, converter.getValue());
converter.setAsText("synchrONoUS");
assertEquals(IndexMaintenancePolicyType.SYNCHRONOUS, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("async");
}
catch (IllegalArgumentException expected) {
assertEquals("(async) is not a valid IndexMaintenancePolicyType!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,86 @@
/*
* 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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link IndexMaintenancePolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexMaintenancePolicyConverter
* @see org.springframework.data.gemfire.IndexMaintenancePolicyType
* @since 1.6.0
*/
public class IndexMaintenancePolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final IndexMaintenancePolicyConverter converter = new IndexMaintenancePolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("asynchronous")).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
assertThat(converter.convert("Synchronous")).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[sync] is not a valid IndexMaintenancePolicyType");
converter.convert("sync");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("aSynchronous");
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.ASYNCHRONOUS);
converter.setAsText("synchrONoUS");
assertThat(converter.getValue()).isEqualTo(IndexMaintenancePolicyType.SYNCHRONOUS);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[async] is not a valid IndexMaintenancePolicyType");
converter.setAsText("async");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,87 +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.assertNull;
import org.junit.After;
import org.junit.Test;
/**
* The IndexTypeConverterTest class is a test suite of test cases testing the contract and functionality
* of the IndexTypeConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexType
* @see org.springframework.data.gemfire.IndexTypeConverter
* @since 1.5.2
*/
public class IndexTypeConverterTest {
private final IndexTypeConverter converter = new IndexTypeConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(IndexType.FUNCTIONAL, converter.convert("FUNCTIONAL"));
assertEquals(IndexType.HASH, converter.convert("hASh"));
assertEquals(IndexType.KEY, converter.convert("Key"));
assertEquals(IndexType.PRIMARY_KEY, converter.convert("primary_KEY"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertWithIllegalValue() {
try {
converter.convert("function");
}
catch (IllegalArgumentException expected) {
assertEquals("(function) is not a valid IndexType!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
assertNull(converter.getValue());
converter.setAsText("HasH");
assertEquals(IndexType.HASH, converter.getValue());
converter.setAsText("key");
assertEquals(IndexType.KEY, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("invalid");
}
catch (IllegalArgumentException expected) {
assertEquals("(invalid) is not a valid IndexType!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link IndexTypeConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexType
* @see org.springframework.data.gemfire.IndexTypeConverter
* @since 1.5.2
*/
public class IndexTypeConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final IndexTypeConverter converter = new IndexTypeConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("FUNCTIONAL")).isEqualTo(IndexType.FUNCTIONAL);
assertThat(converter.convert("hASh")).isEqualTo(IndexType.HASH);
assertThat(converter.convert("hASH")).isEqualTo(IndexType.HASH);
assertThat(converter.convert("Key")).isEqualTo(IndexType.KEY);
assertThat(converter.convert("primary_KEY")).isEqualTo(IndexType.PRIMARY_KEY);
}
@Test
public void convertWithIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[function] is not a valid IndexType");
converter.convert("function");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("HasH");
assertThat(converter.getValue()).isEqualTo(IndexType.HASH);
converter.setAsText("key");
assertThat(converter.getValue()).isEqualTo(IndexType.KEY);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[invalid] is not a valid IndexType");
converter.setAsText("invalid");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,88 +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.assertNull;
import org.junit.After;
import org.junit.Test;
import com.gemstone.gemfire.cache.InterestPolicy;
/**
* 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.InterestPolicyConverter
* @see com.gemstone.gemfire.cache.InterestPolicy
* @since 1.6.0
*/
public class InterestPolicyConverterTest {
private InterestPolicyConverter converter = new InterestPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
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 testConvertIllegalValue() {
try {
converter.convert("invalid_value");
}
catch (IllegalArgumentException expected) {
assertEquals("(invalid_value) is not a valid InterestPolicy!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
converter.setAsText("aLl");
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("(none) is not a valid InterestPolicy!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.InterestPolicy;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link InterestPolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.InterestPolicyConverter
* @see com.gemstone.gemfire.cache.InterestPolicy
* @since 1.6.0
*/
public class InterestPolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private InterestPolicyConverter converter = new InterestPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("all")).isEqualTo(InterestPolicy.ALL);
assertThat(converter.convert("Cache_Content")).isEqualTo(InterestPolicy.CACHE_CONTENT);
assertThat(converter.convert("CACHE_ConTent")).isEqualTo(InterestPolicy.CACHE_CONTENT);
assertThat(converter.convert("ALL")).isEqualTo(InterestPolicy.ALL);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[invalid_value] is not a valid InterestPolicy");
converter.convert("invalid_value");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("aLl");
assertThat(converter.getValue()).isEqualTo(InterestPolicy.ALL);
converter.setAsText("Cache_CoNTeNT");
assertThat(converter.getValue()).isEqualTo(InterestPolicy.CACHE_CONTENT);
}
@Test
public void setAsTextWithInvalidValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[none] is not a valid InterestPolicy");
converter.setAsText("none");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,88 +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.assertNull;
import org.junit.After;
import org.junit.Test;
import com.gemstone.gemfire.cache.Scope;
/**
* The ScopeConverterTest class is a test suite of test cases testing the contract and functionality
* of the ScopeConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.ScopeConverter
* @since 1.6.0
*/
public class ScopeConverterTest {
private final ScopeConverter converter = new ScopeConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(Scope.DISTRIBUTED_ACK, converter.convert("distributed-ACK"));
assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.convert(" Distributed_NO-aCK"));
assertEquals(Scope.LOCAL, converter.convert("loCAL "));
assertEquals(Scope.GLOBAL, converter.convert(" GLOBal "));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.convert("illegal-value");
}
catch (IllegalArgumentException expected) {
assertEquals("(illegal-value) is not a valid Scope!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
assertNull(converter.getValue());
converter.setAsText("DisTributeD-nO_Ack");
assertEquals(Scope.DISTRIBUTED_NO_ACK, converter.getValue());
converter.setAsText("distributed-ack");
assertEquals(Scope.DISTRIBUTED_ACK, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("d!5tr!but3d-n0_@ck");
}
catch (IllegalArgumentException expected) {
assertEquals("(d!5tr!but3d-n0_@ck) is not a valid Scope!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.Scope;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link ScopeConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.ScopeConverter
* @see com.gemstone.gemfire.cache.Scope
* @since 1.6.0
*/
public class ScopeConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final ScopeConverter converter = new ScopeConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("distributed-ACK")).isEqualTo(Scope.DISTRIBUTED_ACK);
assertThat(converter.convert(" Distributed_NO-aCK")).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
assertThat(converter.convert("loCAL ")).isEqualTo(Scope.LOCAL);
assertThat(converter.convert(" GLOBal ")).isEqualTo(Scope.GLOBAL);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[illegal-value] is not a valid Scope");
converter.convert("illegal-value");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("DisTributeD-nO_Ack");
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_NO_ACK);
converter.setAsText("distributed-ack");
assertThat(converter.getValue()).isEqualTo(Scope.DISTRIBUTED_ACK);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[d!5tr!but3d-n0_@ck] is not a valid Scope");
converter.setAsText("d!5tr!but3d-n0_@ck");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -60,7 +60,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.support.ConnectionEndpoint;
import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.data.gemfire.util.DistributedSystemUtils;

View File

@@ -43,7 +43,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.io.Resource;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.EvictionAttributes;

View File

@@ -1,90 +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.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());
}
}
}

View File

@@ -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.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.InterestResultPolicy;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link InterestResultPolicyConverter}.
*
* @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 InterestResultPolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final InterestResultPolicyConverter converter = new InterestResultPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("NONE")).isEqualTo(InterestResultPolicy.NONE);
assertThat(converter.convert("kEyS_ValUes")).isEqualTo(InterestResultPolicy.KEYS_VALUES);
assertThat(converter.convert("nONe")).isEqualTo(InterestResultPolicy.NONE);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy");
converter.convert("illegal_value");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("NOne");
assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.NONE);
converter.setAsText("KeYs");
assertThat(converter.getValue()).isEqualTo(InterestResultPolicy.KEYS);
}
@Test
public void setAsTextWithIllegalValue() {
try {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[illegal_value] is not a valid InterestResultPolicy");
converter.setAsText("illegal_value");
}
finally {
assertThat(converter.getValue()).isNull();
}
}
}

View File

@@ -1,153 +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.config;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.matches;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* The AbstractRegionParserTest class is a test suite of test cases testing the contract and functionality of the
* AbstractRegionParser class.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.config.AbstractRegionParser
* @since 1.3.3
*/
public class AbstractRegionParserTest {
private AbstractRegionParser regionParser = new TestRegionParser();
@Test
public void testIsSubRegionWhen() {
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn("partitioned-region");
assertTrue(regionParser.isSubRegion(mockElement));
}
@Test
public void testIsSubRegionWhenLocalNameIsNull() {
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn(null);
assertFalse(regionParser.isSubRegion(mockElement));
}
@Test
public void testIsSubRegionWhenLocalNameDoesNotEndWithRegion() {
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn("disk-store");
assertFalse(regionParser.isSubRegion(mockElement));
}
@Test
public void testValidateDataPolicyShortcutAttributesMutualExclusion() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement, never()).hasAttribute(eq("shortcut"));
}
@Test
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement).hasAttribute(eq("shortcut"));
}
@Test
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithShortcut() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement, never()).hasAttribute(eq("shortcut"));
}
@Test
public void testValidateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() {
Element mockElement = mock(Element.class);
XmlReaderContext mockReaderContext = mock(XmlReaderContext.class);
ParserContext mockParserContext = new ParserContext(mockReaderContext, null);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
when(mockElement.getTagName()).thenReturn("local-region");
new TestRegionParser().validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext);
verify(mockReaderContext).error(
eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."),
eq(mockElement));
}
protected static class TestRegionParser extends AbstractRegionParser {
@Override
protected Class<?> getRegionFactoryClass() {
return getClass();
}
@Override
protected void doParseRegion(final Element element, final ParserContext parserContext,
final BeanDefinitionBuilder builder, final boolean subRegion) {
throw new UnsupportedOperationException("Not Implemented!");
}
}
}

View File

@@ -1,143 +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.config;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import org.apache.commons.logging.Log;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import com.gemstone.gemfire.cache.query.MultiIndexCreationException;
import com.gemstone.gemfire.cache.query.QueryService;
/**
* The CreateDefinedIndexesApplicationListenerTest class is a test suite of test cases testing the contract
* and functionality of the CreateDefinedIndexesApplicationListener class.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.event.ContextRefreshedEvent
* @see org.springframework.data.gemfire.config.CreateDefinedIndexesApplicationListener
* @see com.gemstone.gemfire.cache.query.QueryService
* @since 1.7.0
*/
public class CreateDefinedIndexesApplicationListenerTest {
private CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener();
@Test
public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception {
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockApplicationContext");
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockContextRefreshedEvent");
QueryService mockQueryService = mock(QueryService.class,
"testCreateDefinedIndexesCalledOnContextRefreshedEvent.MockQueryService");
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
.thenReturn(true);
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
eq(QueryService.class))).thenReturn(mockQueryService);
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(
eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class));
verify(mockQueryService, times(1)).createDefinedIndexes();
}
@Test
public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception {
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockApplicationContext");
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockContextRefreshedEvent");
QueryService mockQueryService = mock(QueryService.class,
"testCreateDefinedIndexesUsingClientCacheLocalQueryService.MockQueryService");
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
.thenReturn(false);
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
eq(QueryService.class))).thenReturn(mockQueryService);
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class));
verify(mockQueryService, never()).createDefinedIndexes();
}
@Test
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
ApplicationContext mockApplicationContext = mock(ApplicationContext.class,
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockApplicationContext");
ContextRefreshedEvent mockEvent = mock(ContextRefreshedEvent.class,
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockContextRefreshedEvent");
QueryService mockQueryService = mock(QueryService.class,
"testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockQueryService");
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
when(mockApplicationContext.containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE)))
.thenReturn(true);
when(mockApplicationContext.getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE),
eq(QueryService.class))).thenReturn(mockQueryService);
when(mockQueryService.createDefinedIndexes()).thenThrow(new MultiIndexCreationException(
new HashMap<String, Exception>(Collections.singletonMap("TestKey", new RuntimeException("TEST")))));
final Log mockLog = mock(Log.class, "testCreateDefinedIndexesThrowingAnExceptionIsLogged.MockLog");
CreateDefinedIndexesApplicationListener listener = new CreateDefinedIndexesApplicationListener() {
@Override Log initLogger() {
return mockLog;
}
};
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE));
verify(mockApplicationContext, times(1)).getBean(eq(GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE), eq(QueryService.class));
verify(mockLog, times(1)).warn(startsWith("unable to create defined Indexes (if any):"));
}
}

View File

@@ -1,255 +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.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.data.gemfire.test.support.IdentifierSequence;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
/**
* The CreateDefinedIndexesIntegrationTest class is a test suite of test cases testing the functional behavior
* of the GemFire Cache Region Index "definition" and subsequent "creation" step in a SDG-configured application
* using a combination of "defined" and "created" Index beans in a Spring context.
*
* @author John Blum
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.query.Index
* @see com.gemstone.gemfire.cache.query.QueryService
* @since 1.7.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class CreateDefinedIndexesIntegrationTest {
private static final List<String> definedIndexNames = new ArrayList<String>(3);
@Autowired
private Cache gemfireCache;
@Autowired
@Qualifier("IdIdx")
private Index id;
@Autowired
@Qualifier("BirthDateIdx")
private Index birthDate;
@Autowired
@Qualifier("FullNameIdx")
private Index fullName;
@Autowired
@Qualifier("LastNameIdx")
private Index lastName;
@Resource(name = "People")
private Region<Long, Person> people;
protected static Date createBirthDate(final int year, final int month, final int dayOfMonth) {
Calendar birthDate = Calendar.getInstance();
birthDate.clear();
birthDate.set(Calendar.YEAR, year);
birthDate.set(Calendar.MONTH, month);
birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
return birthDate.getTime();
}
protected static Person createPerson(final String firstName, final String lastName, final Date birthDate) {
return createPerson(IdentifierSequence.nextId(), firstName, lastName, birthDate);
}
protected static Person createPerson(final Long id, final String firstName, final String lastName, final Date birthDate) {
return new Person(id, firstName, lastName, birthDate);
}
protected static Person put(final Region<Long, Person> people, final Person person) {
people.put(person.getId(), person);
return person;
}
@Before
public void setup() {
put(people, createPerson("Jon", "Doe", createBirthDate(1989, Calendar.NOVEMBER, 11)));
put(people, createPerson("Jane", "Doe", createBirthDate(1991, Calendar.APRIL, 4)));
put(people, createPerson("Pie", "Doe", createBirthDate(2008, Calendar.JUNE, 21)));
put(people, createPerson("Cookie", "Doe", createBirthDate(2008, Calendar.AUGUST, 14)));
}
@Test
public void indexesCreated() {
QueryService queryService = gemfireCache.getQueryService();
//System.out.printf("GemFire Cache Indexes: %1$s%n", queryService.getIndexes());
//System.out.printf("/Example Region Indexes: %1$s%n", queryService.getIndexes(people));
assertTrue(definedIndexNames.containsAll(Arrays.asList(id.getName(), birthDate.getName(), fullName.getName())));
assertEquals(id, queryService.getIndex(people, id.getName()));
assertEquals(birthDate, queryService.getIndex(people, birthDate.getName()));
assertEquals(fullName, queryService.getIndex(people, fullName.getName()));
assertEquals(lastName, queryService.getIndex(people, lastName.getName()));
}
public static class IndexBeanPostProcessor implements BeanPostProcessor {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Index) {
if ("LastNameIdx".equals(beanName)) {
assertTrue(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean));
assertTrue(beanName.equalsIgnoreCase(((Index) bean).getName()));
}
else {
definedIndexNames.add(beanName);
}
}
return bean;
}
}
public static class Person implements Serializable {
protected static final String BIRTH_DATE_FORMAT_PATTERN = "yyyy/MM/dd";
private Date birthDate;
private Long id;
private String firstName;
private String lastName;
public Person() {
}
public Person(final Long id) {
this.id = id;
}
public Person(final String firstName, final String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public Person(final String firstName, final String lastName, final Date birthDate) {
this(firstName, lastName);
this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null);
}
public Person(final Long id, final String firstName, final String lastName, final Date birthDate) {
this(firstName, lastName, birthDate);
this.id = id;
}
public Long getId() {
return id;
}
public Date getBirthDate() {
return birthDate;
}
public String getFirstName() {
return firstName;
}
public String getFullName() {
return String.format("%1$s %2$s", getFirstName(), getLastName());
}
public String getLastName() {
return lastName;
}
protected static boolean equalsIgnoreNull(final Object obj1, final Object obj2) {
return (obj1 == null ? obj2 == null : obj1.equals(obj2));
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Person)) {
return false;
}
Person that = (Person) obj;
return equalsIgnoreNull(getId(), that.getId())
&& (ObjectUtils.nullSafeEquals(getBirthDate(), that.getBirthDate()))
&& (ObjectUtils.nullSafeEquals(getFirstName(), that.getFirstName())
&& (ObjectUtils.nullSafeEquals(getLastName(), that.getLastName())));
}
@Override
public int hashCode() {
int hashValue = 17;
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getId());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getBirthDate());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName());
return hashValue;
}
protected static String toString(final Date dateTime, final String DATE_FORMAT_PATTERN) {
return (dateTime == null ? null : new SimpleDateFormat(DATE_FORMAT_PATTERN).format(dateTime));
}
@Override
public String toString() {
return String.format("{ @type = %1$s, id = %2$d, firstName = %3$s, lastName = %4$s, birthDate = %5$s }",
getClass().getName(), getId(), getFirstName(), getLastName(),
toString(getBirthDate(), BIRTH_DATE_FORMAT_PATTERN));
}
}
}

View File

@@ -1,68 +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.config;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
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 org.springframework.util.FileSystemUtils;
/**
* The DiskStoreBeanPostProcessorTest class is a test suite of test cases testing the contract and functionality of
* the DiskStoreBeanPostProcessor class.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.data.gemfire.config.DiskStoreBeanPostProcessor
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
public class DiskStoreBeanPostProcessorTest {
@BeforeClass
public static void testSuiteSetup() {
assertTrue("Failed to created directory './gemfire/disk-stores/local/ds2'!",
new File("./gemfire/disk-stores/local/ds2").mkdirs());
}
@AfterClass
public static void testSuiteTearDown() {
assertTrue("Failed to delete directory './gemfire'!", FileSystemUtils.deleteRecursively(new File("./gemfire")));
assertTrue("Failed to delete directory './gfe'!", FileSystemUtils.deleteRecursively(new File("./gfe")));
}
@Test
public void testDiskStoreDirectoryLocationsExist() {
assertTrue(new File("./gemfire/disk-stores/ds1").isDirectory());
assertTrue(new File("./gemfire/disk-stores/local/ds2").isDirectory());
assertTrue(new File("./gemfire/disk-stores/remote/ds2").isDirectory());
assertTrue(new File("./gfe/ds/local/store3").isDirectory());
}
}

View File

@@ -0,0 +1,267 @@
/*
* Copyright 2012 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.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.Region;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.data.gemfire.util.CollectionUtils;
/**
* Unit tests for {@link AutoRegionLookupBeanPostProcessor}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.data.gemfire.config.support.AutoRegionLookupBeanPostProcessor
* @since 1.9.0
*/
@RunWith(MockitoJUnitRunner.class)
public class AutoRegionLookupBeanPostProcessorUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor;
@Mock
private ConfigurableListableBeanFactory mockBeanFactory;
@Before
public void setup() {
autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor();
}
protected Region<?, ?> mockRegion(String regionFullPath) {
Region<?, ?> mockRegion = mock(Region.class);
when(mockRegion.getFullPath()).thenReturn(regionFullPath);
when(mockRegion.getName()).thenReturn(toRegionName(regionFullPath));
return mockRegion;
}
protected String toRegionName(String regionFullPath) {
int index = regionFullPath.lastIndexOf(Region.SEPARATOR);
return (index > -1 ? regionFullPath.substring(index + 1) : regionFullPath);
}
@Test
public void setAndGetBeanFactory() {
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
assertThat(autoRegionLookupBeanPostProcessor.getBeanFactory()).isSameAs(mockBeanFactory);
}
@Test
public void setBeanFactoryToIncompatibleBeanFactoryType() {
BeanFactory mockBeanFactory = mock(BeanFactory.class);
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage(String.format("BeanFactory [%1$s] must be an instance of %2$s",
mockBeanFactory.getClass().getName(), ConfigurableListableBeanFactory.class.getSimpleName()));
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
}
@Test
public void setBeanFactoryToNull() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage(String.format("BeanFactory [null] must be an instance of %s",
ConfigurableListableBeanFactory.class.getSimpleName()));
autoRegionLookupBeanPostProcessor.setBeanFactory(null);
}
@Test
public void getBeanFactoryUninitialized() {
exception.expect(IllegalStateException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("BeanFactory was not properly initialized");
autoRegionLookupBeanPostProcessor.getBeanFactory();
}
@Test
public void postProcessBeforeInitializationReturnsBean() {
Object bean = new Object();
assertThat(autoRegionLookupBeanPostProcessor.postProcessBeforeInitialization(bean, "test")).isSameAs(bean);
}
@Test
public void postProcessAfterInitializationWithNonGemFireCacheBean() {
Object bean = new Object();
AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessorSpy =
spy(this.autoRegionLookupBeanPostProcessor);
assertThat(autoRegionLookupBeanPostProcessorSpy.postProcessAfterInitialization(bean, "test")).isSameAs(bean);
verify(autoRegionLookupBeanPostProcessorSpy, never()).registerCacheRegionsAsBeans(any(GemFireCache.class));
}
@Test
public void registerCacheRegionsAsBeansIsSuccessful() {
Set<Region<?, ?>> expected = CollectionUtils.asSet(mockRegion("one"), mockRegion("two"), mockRegion("three"));
final Set<Region<?, ?>> actual = new HashSet<Region<?, ?>>(expected.size());
AutoRegionLookupBeanPostProcessor autoRegionLookupBeanPostProcessor = new AutoRegionLookupBeanPostProcessor() {
@Override void registerCacheRegionAsBean(Region<?, ?> region) {
actual.add(region);
}
};
GemFireCache mockGemFireCache = mock(GemFireCache.class);
when(mockGemFireCache.rootRegions()).thenReturn(expected);
autoRegionLookupBeanPostProcessor.registerCacheRegionsAsBeans(mockGemFireCache);
assertThat(actual).isEqualTo(expected);
verify(mockGemFireCache, times(1)).rootRegions();
for (Region<?, ?> region : expected) {
verifyZeroInteractions(region);
}
}
@Test
public void registerCacheRegionAsBeanIsSuccessful() {
Region<?, ?> mockRegion = mockRegion("Example");
when(mockRegion.subregions(anyBoolean())).thenReturn(Collections.<Region<?, ?>>emptySet());
when(mockBeanFactory.containsBean(anyString())).thenReturn(false);
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRegion);
verify(mockBeanFactory, times(1)).containsBean(eq("Example"));
verify(mockBeanFactory, times(1)).registerSingleton(eq("Example"), eq(mockRegion));
verify(mockRegion, times(1)).getFullPath();
verify(mockRegion, times(1)).getName();
verify(mockRegion, times(1)).subregions(eq(false));
}
@Test
public void registerCacheRegionAsBeanRegistersSubRegionIgnoresRootRegion() {
Region<?, ?> mockRootRegion = mockRegion("Root");
Region<?, ?> mockSubRegion = mockRegion("/Root/Sub");
when(mockRootRegion.subregions(anyBoolean())).thenReturn(CollectionUtils.<Region<?, ?>>asSet(mockSubRegion));
when(mockSubRegion.subregions(anyBoolean())).thenReturn(Collections.<Region<?, ?>>emptySet());
when(mockBeanFactory.containsBean(eq("Root"))).thenReturn(true);
when(mockBeanFactory.containsBean(eq("/Root/Sub"))).thenReturn(false);
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(mockRootRegion);
verify(mockBeanFactory, times(1)).containsBean(eq("Root"));
verify(mockBeanFactory, times(1)).containsBean(eq("/Root/Sub"));
verify(mockBeanFactory, never()).registerSingleton(eq("Root"), eq(mockRootRegion));
verify(mockBeanFactory, times(1)).registerSingleton(eq("/Root/Sub"), eq(mockSubRegion));
verify(mockRootRegion, times(1)).getFullPath();
verify(mockRootRegion, times(1)).getName();
verify(mockRootRegion, times(1)).subregions(eq(false));
verify(mockSubRegion, times(1)).getFullPath();
verify(mockSubRegion, never()).getName();
verify(mockSubRegion, times(1)).subregions(eq(false));
}
@Test
public void registerNullCacheRegionAsBeanDoesNothing() {
autoRegionLookupBeanPostProcessor.setBeanFactory(mockBeanFactory);
autoRegionLookupBeanPostProcessor.registerCacheRegionAsBean(null);
verifyZeroInteractions(mockBeanFactory);
}
@Test
public void getBeanNameReturnsRegionFullPath() {
Region mockRegion = mockRegion("/Parent/Child");
assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("/Parent/Child");
verify(mockRegion, times(1)).getFullPath();
verify(mockRegion, never()).getName();
}
@Test
public void getBeanNameReturnsRegionName() {
Region mockRegion = mockRegion("/Example");
assertThat(autoRegionLookupBeanPostProcessor.getBeanName(mockRegion)).isEqualTo("Example");
verify(mockRegion, times(1)).getFullPath();
verify(mockRegion, times(1)).getName();
}
@Test
public void nullSafeSubRegionsWhenSubRegionsIsNotNull() {
Set<Region<?, ?>> mockSubRegions = CollectionUtils.asSet(mockRegion("one"), mockRegion("two"));
Region mockRegion = mockRegion("parent");
when(mockRegion.subregions(anyBoolean())).thenReturn(mockSubRegions);
assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(mockSubRegions);
verify(mockRegion, times(1)).subregions(eq(false));
}
@Test
public void nullSafeSubRegionsWhenSubRegionsIsNull() {
Region mockRegion = mockRegion("parent");
when(mockRegion.subregions(anyBoolean())).thenReturn(null);
assertThat(autoRegionLookupBeanPostProcessor.nullSafeSubregions(mockRegion)).isEqualTo(Collections.emptySet());
verify(mockRegion, times(1)).subregions(eq(false));
}
}

View File

@@ -15,13 +15,9 @@
*
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.support;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
@@ -33,13 +29,9 @@ import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.internal.matchers.VarargMatcher;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
@@ -47,32 +39,28 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;
import org.springframework.data.gemfire.client.PoolFactoryBean;
import org.springframework.data.gemfire.test.support.MockitoMatchers;
import org.springframework.data.gemfire.util.ArrayUtils;
/**
* The ClientRegionAndPoolBeanFactoryPostProcessorTests class is a test suite of test cases testing the contract
* and functionality of the {@link ClientRegionAndPoolBeanFactoryPostProcessor} class.
* Unit tests for {@link ClientRegionPoolBeanFactoryPostProcessor}.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.data.gemfire.config.ClientRegionAndPoolBeanFactoryPostProcessor
* @see ClientRegionPoolBeanFactoryPostProcessor
* @since 1.8.2
*/
@RunWith(MockitoJUnitRunner.class)
public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
public class ClientRegionPoolBeanFactoryPostProcessorUnitTests {
@Mock
private BeanDefinition mockBeanDefinition;
private ClientRegionAndPoolBeanFactoryPostProcessor beanFactoryPostProcessor =
new ClientRegionAndPoolBeanFactoryPostProcessor();
protected static <T> T[] asArray(T... array) {
return array;
}
private ClientRegionPoolBeanFactoryPostProcessor beanFactoryPostProcessor =
new ClientRegionPoolBeanFactoryPostProcessor();
protected PropertyValue newPropertyValue(String name, Object value) {
return new PropertyValue(name, value);
@@ -82,10 +70,6 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
return new MutablePropertyValues(Arrays.asList(propertyValues));
}
protected Matcher<String> stringArrayMatcher(String... expected) {
return new ArrayMatcher<String>(expected);
}
@Test
public void postProcessBeanFactory() {
BeanDefinition mockClientRegionBeanOne = mock(BeanDefinition.class, "MockClientRegionBeanOne");
@@ -99,16 +83,16 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
when(mockPoolBean.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName());
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(
asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean"));
ArrayUtils.asArray("mockClientRegionBeanOne", "mockClientRegionBeanTwo", "mockGenericBean", "mockPoolBean"));
when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanOne"))).thenReturn(mockClientRegionBeanOne);
when(mockBeanFactory.getBeanDefinition(eq("mockClientRegionBeanTwo"))).thenReturn(mockClientRegionBeanTwo);
when(mockBeanFactory.getBeanDefinition(eq("mockGenericBean"))).thenReturn(mockBeanDefinition);
when(mockBeanFactory.getBeanDefinition(eq("mockPoolBean"))).thenReturn(mockPoolBean);
when(mockClientRegionBeanOne.getDependsOn()).thenReturn(asArray("mockClientCacheBean"));
when(mockClientRegionBeanOne.getDependsOn()).thenReturn(ArrayUtils.asArray("mockClientCacheBean"));
when(mockClientRegionBeanOne.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean")));
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "mockPoolBean")));
when(mockClientRegionBeanTwo.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT")));
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "DEFAULT")));
beanFactoryPostProcessor.postProcessBeanFactory(mockBeanFactory);
@@ -121,8 +105,8 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
verify(mockClientRegionBeanOne, times(1)).getBeanClassName();
verify(mockClientRegionBeanOne, times(1)).getPropertyValues();
verify(mockClientRegionBeanOne, times(1)).getDependsOn();
verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat(stringArrayMatcher(
"mockClientCacheBean", "mockPoolBean")));
verify(mockClientRegionBeanOne, times(1)).setDependsOn(argThat(
MockitoMatchers.stringArrayMatcher("mockClientCacheBean", "mockPoolBean")));
verify(mockClientRegionBeanTwo, times(1)).getBeanClassName();
verify(mockClientRegionBeanTwo, times(1)).getPropertyValues();
verify(mockClientRegionBeanTwo, never()).getDependsOn();
@@ -133,83 +117,43 @@ public class ClientRegionAndPoolBeanFactoryPostProcessorTests {
@Test
public void isClientRegionBeanReturnsFalse() {
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(false));
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isFalse();
verify(mockBeanDefinition, times(1)).getBeanClassName();
}
@Test
public void isClientRegionBeanReturnsTrue() {
when(mockBeanDefinition.getBeanClassName()).thenReturn(ClientRegionFactoryBean.class.getName());
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition), is(true));
assertThat(beanFactoryPostProcessor.isClientRegionBean(mockBeanDefinition)).isTrue();
verify(mockBeanDefinition, times(1)).getBeanClassName();
}
@Test
public void isPoolBeanReturnsFalse() {
when(mockBeanDefinition.getBeanClassName()).thenReturn(Object.class.getName());
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(false));
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isFalse();
verify(mockBeanDefinition, times(1)).getBeanClassName();
}
@Test
public void isPoolBeanReturnsTrue() {
when(mockBeanDefinition.getBeanClassName()).thenReturn(PoolFactoryBean.class.getName());
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition), is(true));
assertThat(beanFactoryPostProcessor.isPoolBean(mockBeanDefinition)).isTrue();
verify(mockBeanDefinition, times(1)).getBeanClassName();
}
@Test
public void getPoolNameWhenPoolNamePropertyIsSpecifiedReturnsPoolBeanName() {
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
ClientRegionPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName")));
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isEqualTo("testPoolName");
verify(mockBeanDefinition, times(1)).getPropertyValues();
}
@Test
public void getPoolNameWhenPoolNamePropertyIsUnspecifiedReturnsNull() {
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues());
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(nullValue(String.class)));
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition)).isNull();
verify(mockBeanDefinition, times(1)).getPropertyValues();
}
@Test
public void getPoolNameReturnsPoolBeanName() {
when(mockBeanDefinition.getPropertyValues()).thenReturn(newPropertyValues(newPropertyValue(
ClientRegionAndPoolBeanFactoryPostProcessor.POOL_NAME_PROPERTY, "testPoolName")));
assertThat(beanFactoryPostProcessor.getPoolName(mockBeanDefinition), is(equalTo("testPoolName")));
verify(mockBeanDefinition, times(1)).getPropertyValues();
}
@Test
public void addDependsOnToExistingDependencies() {
when(mockBeanDefinition.getDependsOn()).thenReturn(asArray("testBeanNameOne", "testBeanNameTwo"));
assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanNameThree"),
is(sameInstance(mockBeanDefinition)));
verify(mockBeanDefinition, times(1)).getDependsOn();
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher(
"testBeanNameOne", "testBeanNameTwo", "testBeanNameThree")));
}
@Test
public void addDependsOnToNonExistingDependencies() {
when(mockBeanDefinition.getDependsOn()).thenReturn(null);
assertThat(beanFactoryPostProcessor.addDependsOn(mockBeanDefinition, "testBeanName"),
is(sameInstance(mockBeanDefinition)));
verify(mockBeanDefinition, times(1)).getDependsOn();
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(stringArrayMatcher("testBeanName")));
}
protected static final class ArrayMatcher<T> extends BaseMatcher<T> implements VarargMatcher {
private final T[] expected;
protected ArrayMatcher(T... expected) {
this.expected = expected;
}
@Override
public boolean matches(Object item) {
Object[] actual = (item instanceof Object[] ? (Object[]) item : asArray(item));
return Arrays.equals(actual, expected);
}
@Override
public void describeTo(Description description) {
description.appendText(String.format("expected (%1$s)", this.expected));
}
}
}

View File

@@ -14,16 +14,21 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.support;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
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.verifyNoMoreInteractions;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.InterestResultPolicy;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -41,34 +46,38 @@ import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
import org.springframework.data.gemfire.support.ConnectionEndpoint;
import org.springframework.data.gemfire.support.ConnectionEndpointList;
import org.springframework.data.gemfire.wan.OrderPolicyConverter;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.InterestResultPolicy;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import org.springframework.util.StringUtils;
/**
* The CustomEditorRegisteringBeanFactoryPostProcessorTest class...
* Unit tests for {@link CustomEditorBeanFactoryPostProcessor}.
*
* @author John Blum
* @see org.junit.Test
* @see CustomEditorRegisteringBeanFactoryPostProcessor
* @see org.mockito.Mockito
* @see CustomEditorBeanFactoryPostProcessor
* @since 1.6.0
*/
@SuppressWarnings("deprecation")
public class CustomEditorRegisteringBeanFactoryPostProcessorTest {
public class CustomEditorBeanFactoryPostProcessorUnitTests {
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
return new ConnectionEndpoint(host, port);
}
@Test
public void customEditorRegistration() {
public void customEditorRegistrationIsSuccessful() {
ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class);
new CustomEditorRegisteringBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
new CustomEditorBeanFactoryPostProcessor().postProcessBeanFactory(mockBeanFactory);
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint.class),
eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointConverter.class));
//verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpoint[].class),
// eq(CustomEditorRegisteringBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class));
// eq(CustomEditorBeanFactoryPostProcessor.ConnectionEndpointArrayToIterableConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(ConnectionEndpointList.class),
eq(CustomEditorBeanFactoryPostProcessor.StringToConnectionEndpointListConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionAction.class),
eq(EvictionActionConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(EvictionPolicyType.class),
@@ -89,32 +98,55 @@ public class CustomEditorRegisteringBeanFactoryPostProcessorTest {
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(Scope.class), eq(ScopeConverter.class));
verify(mockBeanFactory, times(1)).registerCustomEditor(eq(SubscriptionEvictionPolicy.class),
eq(SubscriptionEvictionPolicyConverter.class));
}
protected ConnectionEndpoint newConnectionEndpoint(String host, int port) {
return new ConnectionEndpoint(host, port);
verifyNoMoreInteractions(mockBeanFactory);
}
@Test
@SuppressWarnings("unchecked")
public void connectionEndpointArrayToIterableConversion() {
public void connectionEndpointArrayToIterableConversionIsSuccessful() {
ConnectionEndpoint[] array = {
newConnectionEndpoint("localhost", 10334),
newConnectionEndpoint("localhost", 40404)
};
Iterable<ConnectionEndpoint> iterable = new CustomEditorRegisteringBeanFactoryPostProcessor
Iterable<ConnectionEndpoint> iterable = new CustomEditorBeanFactoryPostProcessor
.ConnectionEndpointArrayToIterableConverter().convert(array);
assertThat(iterable, is(notNullValue()));
assertThat(iterable).isNotNull();
int index = 0;
for (ConnectionEndpoint connectionEndpoint : iterable) {
assertThat(connectionEndpoint, is(equalTo(array[index++])));
assertThat(connectionEndpoint).isEqualTo(array[index++]);
}
assertThat(index, is(equalTo(2)));
assertThat(index).isEqualTo(array.length);
}
@Test
public void stringToConnectionEndpointConversionIsSuccessful() {
String hostPort = "skullbox[54321]";
ConnectionEndpoint connectionEndpoint = new CustomEditorBeanFactoryPostProcessor
.StringToConnectionEndpointConverter().convert(hostPort);
assertThat(connectionEndpoint).isNotNull();
assertThat(connectionEndpoint.getHost()).isEqualTo("skullbox");
assertThat(connectionEndpoint.getPort()).isEqualTo(54321);
}
@Test
public void stringToConnectionEndpointListConversionIsSuccessful() {
String[] hostsPorts = { "toolbox[10334]", "skullbox", "[40404]" };
String source = StringUtils.arrayToCommaDelimitedString(hostsPorts);
ConnectionEndpointList connectionEndpoints = new CustomEditorBeanFactoryPostProcessor
.StringToConnectionEndpointListConverter().convert(source);
assertThat(connectionEndpoints).isNotNull();
assertThat(connectionEndpoints.size()).isEqualTo(hostsPorts.length);
assertThat(connectionEndpoints.findOne("toolbox").getPort()).isEqualTo(10334);
assertThat(connectionEndpoints.findOne("skullbox").getPort()).isEqualTo(0);
assertThat(connectionEndpoints.findOne(40404).getHost()).isEqualTo("localhost");
}
}

View File

@@ -0,0 +1,137 @@
/*
* 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.support;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isA;
import static org.mockito.Matchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.Collections;
import java.util.HashMap;
import com.gemstone.gemfire.cache.query.MultiIndexCreationException;
import com.gemstone.gemfire.cache.query.QueryService;
import org.apache.commons.logging.Log;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
/**
* Unit tests for {@link DefinedIndexesApplicationListener}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see DefinedIndexesApplicationListener
* @since 1.7.0
*/
@RunWith(MockitoJUnitRunner.class)
public class DefinedIndexesApplicationListenerUnitTests {
private static final String QUERY_SERVICE_BEAN_NAME =
GemfireConstants.DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE;
@Mock
private ApplicationContext mockApplicationContext;
@Mock
private ContextRefreshedEvent mockEvent;
private DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener();
@Mock
private QueryService mockQueryService;
@Before
public void setup() {
when(mockEvent.getApplicationContext()).thenReturn(mockApplicationContext);
}
protected <K, V> HashMap<K, V> newHashMap(K key, V value) {
return new HashMap<K, V>(Collections.singletonMap(key, value));
}
protected MultiIndexCreationException newMultiIndexCreationException(String key, Exception cause) {
return new MultiIndexCreationException(newHashMap(key, cause));
}
@Test
public void createDefinedIndexesCalledOnContextRefreshedEvent() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
.thenReturn(mockQueryService);
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
verify(mockQueryService, times(1)).createDefinedIndexes();
}
@Test
public void createDefinedIndexesNotCalledOnContextRefreshedEvent() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(false);
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
verify(mockApplicationContext, never()).getBean(anyString(), any(QueryService.class));
verify(mockQueryService, never()).createDefinedIndexes();
}
@Test
public void createDefinedIndexesThrowingAnExceptionIsLogged() throws Exception {
when(mockApplicationContext.containsBean(eq(QUERY_SERVICE_BEAN_NAME))).thenReturn(true);
when(mockApplicationContext.getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class)))
.thenReturn(mockQueryService);
when(mockQueryService.createDefinedIndexes())
.thenThrow(newMultiIndexCreationException("TestKey", new RuntimeException("TEST")));
final Log mockLog = mock(Log.class);
DefinedIndexesApplicationListener listener = new DefinedIndexesApplicationListener() {
@Override Log initLogger() {
return mockLog;
}
};
listener.onApplicationEvent(mockEvent);
verify(mockEvent, times(1)).getApplicationContext();
verify(mockApplicationContext, times(1)).containsBean(eq(QUERY_SERVICE_BEAN_NAME));
verify(mockApplicationContext, times(1)).getBean(eq(QUERY_SERVICE_BEAN_NAME), eq(QueryService.class));
verify(mockQueryService, times(1)).createDefinedIndexes();
verify(mockLog, times(1)).warn(startsWith("Failed to create pre-defined Indexes:"),
isA(MultiIndexCreationException.class));
}
}

View File

@@ -0,0 +1,227 @@
/*
* 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.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.gemfire.test.model.Person.newBirthDate;
import static org.springframework.data.gemfire.test.model.Person.newPerson;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.GemFireCache;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
import com.gemstone.gemfire.cache.query.QueryService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.gemfire.IndexFactoryBean;
import org.springframework.data.gemfire.IndexType;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
import org.springframework.data.gemfire.test.model.Gender;
import org.springframework.data.gemfire.test.model.Person;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration tests for {@link DefinedIndexesApplicationListener}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.query.Index
* @see com.gemstone.gemfire.cache.query.QueryService
* @since 1.7.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class DefinedIndexesIntegrationTests {
private static final List<String> definedIndexNames = new ArrayList<String>(3);
@Autowired
private Cache gemfireCache;
@Autowired
@Qualifier("IdIdx")
private Index id;
@Autowired
@Qualifier("BirthDateIdx")
private Index birthDate;
@Autowired
@Qualifier("LastNameIdx")
private Index lastName;
@Autowired
@Qualifier("NameIdx")
private Index name;
@Resource(name = "People")
private Region<Long, Person> people;
protected static Person put(Region<Long, Person> people, Person person) {
people.put(person.getId(), person);
return person;
}
@Before
public void setup() {
put(people, newPerson("Jon", "Doe", newBirthDate(1989, Calendar.NOVEMBER, 11), Gender.MALE));
put(people, newPerson("Jane", "Doe", newBirthDate(1991, Calendar.APRIL, 4), Gender.FEMALE));
put(people, newPerson("Pie", "Doe", newBirthDate(2008, Calendar.JUNE, 21), Gender.FEMALE));
put(people, newPerson("Cookie", "Doe", newBirthDate(2008, Calendar.AUGUST, 14), Gender.FEMALE));
}
@Test
public void indexesCreated() {
QueryService queryService = gemfireCache.getQueryService();
List<String> expectedDefinedIndexNames = Arrays.asList(id.getName(), birthDate.getName(), name.getName());
assertThat(definedIndexNames).isEqualTo(expectedDefinedIndexNames);
assertThat(id).isEqualTo(queryService.getIndex(people, id.getName()));
assertThat(birthDate).isEqualTo(queryService.getIndex(people, birthDate.getName()));
assertThat(lastName).isEqualTo(queryService.getIndex(people, lastName.getName()));
assertThat(name).isEqualTo(queryService.getIndex(people, name.getName()));
}
@PeerCacheApplication(logLevel = "warning")
static class DefinedIndexesConfiguration {
@Bean
// TODO remove when the Annotation config model includes support
DefinedIndexesApplicationListener indexApplicationListener() {
return new DefinedIndexesApplicationListener();
}
@Bean
BeanPostProcessor indexBeanPostProcessor() {
return new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Index) {
if ("LastNameIdx".equals(beanName)) {
assertThat(CacheFactory.getAnyInstance().getQueryService().getIndexes().contains(bean)).isTrue();
assertThat(beanName).isEqualToIgnoringCase(((Index) bean).getName());
}
else {
definedIndexNames.add(beanName);
}
}
return bean;
}
};
}
@Bean(name = "People")
PartitionedRegionFactoryBean<Long, Person> peopleRegion(Cache gemfireCache) {
PartitionedRegionFactoryBean<Long, Person> peopleRegion = new PartitionedRegionFactoryBean<Long, Person>();
peopleRegion.setCache(gemfireCache);
peopleRegion.setClose(false);
peopleRegion.setPersistent(false);
return peopleRegion;
}
@Bean(name = "IdIdx")
@DependsOn("People")
IndexFactoryBean idIndex(GemFireCache gemFireCache) {
IndexFactoryBean idIndex = new IndexFactoryBean();
idIndex.setCache(gemFireCache);
idIndex.setDefine(true);
idIndex.setExpression("id");
idIndex.setFrom("/People");
idIndex.setName("IdIdx");
idIndex.setType(IndexType.KEY);
return idIndex;
}
@Bean(name = "BirthDateIdx")
@DependsOn("People")
IndexFactoryBean birthDateIndex(GemFireCache gemFireCache) {
IndexFactoryBean birthDateIndex = new IndexFactoryBean();
birthDateIndex.setCache(gemFireCache);
birthDateIndex.setDefine(true);
birthDateIndex.setExpression("birthDate");
birthDateIndex.setFrom("/People");
birthDateIndex.setName("BirthDateIdx");
birthDateIndex.setType(IndexType.HASH);
return birthDateIndex;
}
@Bean(name = "LastNameIdx")
@DependsOn("People")
IndexFactoryBean lastNameIndex(GemFireCache gemFireCache) {
IndexFactoryBean lastNameIndex = new IndexFactoryBean();
lastNameIndex.setCache(gemFireCache);
lastNameIndex.setExpression("lastName");
lastNameIndex.setFrom("/People");
lastNameIndex.setName("LastNameIdx");
lastNameIndex.setType(IndexType.HASH);
return lastNameIndex;
}
@Bean(name = "NameIdx")
@DependsOn("People")
IndexFactoryBean nameIndex(GemFireCache gemFireCache) {
IndexFactoryBean nameIndex = new IndexFactoryBean();
nameIndex.setCache(gemFireCache);
nameIndex.setDefine(true);
nameIndex.setExpression("name");
nameIndex.setFrom("/People");
nameIndex.setName("NameIdx");
nameIndex.setType(IndexType.FUNCTIONAL);
return nameIndex;
}
}
}

View File

@@ -0,0 +1,108 @@
/*
* 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.support;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import com.gemstone.gemfire.cache.GemFireCache;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.DiskStoreFactoryBean;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.FileSystemUtils;
/**
* Integration tests for {@link DiskStoreBeanPostProcessor}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.config.support.DiskStoreBeanPostProcessor
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class DiskStoreBeanPostProcessorIntegrationTests {
@BeforeClass
public static void testSuiteSetup() {
assertThat(new File("./gemfire/disk-stores/ds2/local").mkdirs()).isTrue();
}
@AfterClass
public static void testSuiteTearDown() {
assertThat(FileSystemUtils.deleteRecursively(new File("./gemfire"))).isTrue();
assertThat(FileSystemUtils.deleteRecursively(new File("./gfe"))).isTrue();
}
@Test
public void diskStoreDirectoriesExist() {
assertThat(new File("./gemfire/disk-stores/ds1").isDirectory()).isTrue();
assertThat(new File("./gemfire/disk-stores/ds2/local").isDirectory()).isTrue();
assertThat(new File("./gemfire/disk-stores/ds2/remote").isDirectory()).isTrue();
assertThat(new File("./gfe/ds/store3/local").isDirectory()).isTrue();
}
@PeerCacheApplication(logLevel = "warning")
@SuppressWarnings("unused")
static class DiskStoreBeanPostProcessorConfiguration {
DiskStoreFactoryBean.DiskDir newDiskDir(String location) {
return new DiskStoreFactoryBean.DiskDir(location);
}
@Bean
// TODO remove when the Annotation config model includes support
DiskStoreBeanPostProcessor diskStoreBeanPostProcessor() {
return new DiskStoreBeanPostProcessor();
}
@Bean
DiskStoreFactoryBean diskStoreOne(GemFireCache gemfireCache) {
DiskStoreFactoryBean diskStoreOne = new DiskStoreFactoryBean();
diskStoreOne.setCache(gemfireCache);
diskStoreOne.setDiskDirs(Collections.singletonList(newDiskDir("./gemfire/disk-stores/ds1")));
return diskStoreOne;
}
@Bean
DiskStoreFactoryBean diskStoreTwo(GemFireCache gemfireCache) {
DiskStoreFactoryBean diskStoreTwo = new DiskStoreFactoryBean();
diskStoreTwo.setCache(gemfireCache);
diskStoreTwo.setDiskDirs(Arrays.asList(newDiskDir("./gemfire/disk-stores/ds2/local"),
newDiskDir("./gemfire/disk-stores/ds2/remote")));
return diskStoreTwo;
}
@Bean
DiskStoreFactoryBean diskStoreThree(GemFireCache gemfireCache) {
DiskStoreFactoryBean diskStoreThree = new DiskStoreFactoryBean();
diskStoreThree.setCache(gemfireCache);
diskStoreThree.setDiskDirs(Collections.singletonList(newDiskDir("./gfe/ds/store3/local")));
return diskStoreThree;
}
}
}

View File

@@ -14,12 +14,9 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock;
@@ -32,6 +29,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -40,54 +42,45 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.data.gemfire.CacheFactoryBean;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
import com.gemstone.gemfire.internal.cache.PartitionedRegion;
import org.springframework.data.gemfire.util.ArrayUtils;
/**
* The PdxDiskStoreAwareBeanFactoryPostProcessorTest class is a test suite of test cases testing the functionality
* of the PdxDiskStoreAwareBeanFactoryPostProcessor class.
* Unit tests for {@link PdxDiskStoreAwareBeanFactoryPostProcessor}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.config.PdxDiskStoreAwareBeanFactoryPostProcessor
* @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor
* @see com.gemstone.gemfire.cache.DiskStore
* @see com.gemstone.gemfire.cache.Region
* @see com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue
* @since 1.3.3
*/
public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
protected static String[] toStringArray(final Collection<String> collection) {
protected static boolean isBeanType(BeanDefinition beanDefinition, Class<?> beanType) {
return (beanDefinition instanceof AbstractBeanDefinition
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));
}
protected static String[] toStringArray(Collection<String> collection) {
return collection.toArray(new String[collection.size()]);
}
protected static boolean isEmpty(final Object[] array) {
return (array == null || array.length == 0);
}
protected static boolean isBeanType(final BeanDefinition beanDefinition, final Class<?> beanType) {
return (beanDefinition instanceof AbstractBeanDefinition
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));
}
protected ConfigurableListableBeanFactory createMockBeanFactory(final Map<String, BeanDefinition> beanDefinitions) {
protected ConfigurableListableBeanFactory mockBeanFactory(final Map<String, BeanDefinition> beanDefinitions) {
final ConfigurableListableBeanFactory mockBeanFactory = mock(ConfigurableListableBeanFactory.class);
when(mockBeanFactory.getBeanDefinitionNames()).thenReturn(toStringArray(beanDefinitions.keySet()));
when(mockBeanFactory.getBeanNamesForType(isA(Class.class))).then(new Answer<String[]>() {
@Override
public String[] answer(final InvocationOnMock invocation) throws Throwable {
public String[] answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assertNotNull(arguments);
assertTrue(arguments.length == 1);
assertTrue(arguments[0] instanceof Class);
assertThat(arguments).isNotNull();
assertThat(arguments.length).isEqualTo(1);
assertThat(arguments[0]).isInstanceOf(Class.class);
Class beanType = (Class) arguments[0];
@@ -107,10 +100,10 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
when(mockBeanFactory.getBeanDefinition(anyString())).then(new Answer<BeanDefinition>() {
@Override
public BeanDefinition answer(final InvocationOnMock invocation) throws Throwable {
public BeanDefinition answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
assertNotNull(arguments);
assertTrue(arguments.length == 1);
assertThat(arguments).isNotNull();
assertThat(arguments.length).isEqualTo(1);
return beanDefinitions.get(String.valueOf(arguments[0]));
}
});
@@ -118,7 +111,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
return mockBeanFactory;
}
protected static BeanDefinitionBuilder createBeanDefinitionBuilder(Object beanClassObject, String... dependencies) {
protected static BeanDefinitionBuilder newBeanDefinitionBuilder(Object beanClassObject, String... dependencies) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
if (beanClassObject instanceof Class) {
@@ -140,28 +133,28 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
}
protected static void assertDependencies(BeanDefinition beanDefinition, String... expectedDependencies) {
assertFalse(isEmpty(beanDefinition.getDependsOn()));
assertTrue(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies)));
assertThat(ArrayUtils.isEmpty(beanDefinition.getDependsOn())).isFalse();
assertThat(Arrays.asList(beanDefinition.getDependsOn()).equals(Arrays.asList(expectedDependencies))).isTrue();
}
protected BeanDefinition defineBean(String beanClassName, String... dependencies) {
return createBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition();
return newBeanDefinitionBuilder(beanClassName, dependencies).getBeanDefinition();
}
protected BeanDefinition defineCache() {
return createBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition();
return newBeanDefinitionBuilder(CacheFactoryBean.class).getBeanDefinition();
}
protected BeanDefinition defineAsyncEventQueue(String... dependencies) {
return createBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition();
return newBeanDefinitionBuilder(AsyncEventQueue.class, dependencies).getBeanDefinition();
}
protected BeanDefinition defineDiskStore(String... dependencies) {
return createBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition();
return newBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition();
}
protected BeanDefinition defineRegion(Class regionClass, String... dependencies) {
return createBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition();
return newBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition();
}
protected BeanDefinition definePartitionedRegion(String... dependencies) {
@@ -173,32 +166,33 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
}
@Test(expected = IllegalArgumentException.class)
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() {
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithBlankDiskStoreName() {
new PdxDiskStoreAwareBeanFactoryPostProcessor(" ");
}
@Test(expected = IllegalArgumentException.class)
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() {
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithEmptyDiskStoreName() {
new PdxDiskStoreAwareBeanFactoryPostProcessor("");
}
@Test(expected = IllegalArgumentException.class)
public void testCreatePdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() {
public void createPdxDiskStoreAwareBeanFactoryPostProcessorWithNullDiskStoreName() {
new PdxDiskStoreAwareBeanFactoryPostProcessor(null);
}
@Test
public void testInitializedPdxDiskStoreAwareBeanFactoryPostProcessor() {
public void initializedPdxDiskStoreAwareBeanFactoryPostProcessor() {
PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
new PdxDiskStoreAwareBeanFactoryPostProcessor("testPdxDiskStoreName");
assertNotNull(postProcessor);
assertEquals("testPdxDiskStoreName", postProcessor.getPdxDiskStoreName());
assertThat(postProcessor).isNotNull();
assertThat(postProcessor.getPdxDiskStoreName()).isEqualTo("testPdxDiskStoreName");
}
@Test
public void testPostProcessBeanFactory() {
final Map<String, BeanDefinition> beanDefinitions = new HashMap<String, BeanDefinition>(13);
@SuppressWarnings("all")
public void postProcessBeanFactory() {
Map<String, BeanDefinition> beanDefinitions = new HashMap<String, BeanDefinition>(13);
beanDefinitions.put("someBean", defineBean("org.company.app.domain.SomeBean", "someOtherBean"));
beanDefinitions.put("gemfireCache", defineCache());
@@ -217,17 +211,17 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
beanDefinitions.put("region3", definePartitionedRegion());
beanDefinitions.put("region4", definePartitionedRegion("queue2"));
final ConfigurableListableBeanFactory mockBeanFactory = createMockBeanFactory(beanDefinitions);
ConfigurableListableBeanFactory mockBeanFactory = mockBeanFactory(beanDefinitions);
final PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
PdxDiskStoreAwareBeanFactoryPostProcessor postProcessor =
new PdxDiskStoreAwareBeanFactoryPostProcessor("pdxDiskStore");
postProcessor.postProcessBeanFactory(mockBeanFactory);
assertDependencies(beanDefinitions.get("someBean"), "someOtherBean");
assertTrue(isEmpty(beanDefinitions.get("gemfireCache").getDependsOn()));
assertTrue(isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn()));
assertTrue(isEmpty(beanDefinitions.get("someOtherBean").getDependsOn()));
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("gemfireCache").getDependsOn())).isTrue();
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("pdxDiskStore").getDependsOn())).isTrue();
assertThat(ArrayUtils.isEmpty(beanDefinitions.get("someOtherBean").getDependsOn())).isTrue();
assertDependencies(beanDefinitions.get("queue1"), "pdxDiskStore", "someOtherBean");
assertDependencies(beanDefinitions.get("overflowDiskStore"), "pdxDiskStore");
assertDependencies(beanDefinitions.get("region1"), "pdxDiskStore", "overflowDiskStore");
@@ -241,5 +235,4 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorTest {
assertDependencies(beanDefinitions.get("region3"), "pdxDiskStore");
assertDependencies(beanDefinitions.get("region4"), "pdxDiskStore", "queue2");
}
}

View File

@@ -0,0 +1,276 @@
/*
* 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.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Matchers.matches;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* Unit tests for {@link AbstractRegionParser}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.springframework.data.gemfire.config.xml.AbstractRegionParser
* @since 1.3.3
*/
// TODO add more tests
public class AbstractRegionParserUnitTests {
private AbstractRegionParser regionParser = new TestRegionParser();
protected void assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(String localName) {
Element mockElement = mock(Element.class);
when(mockElement.getLocalName()).thenReturn(localName);
assertThat(regionParser.isRegionTemplate(mockElement)).isEqualTo(nullSafeEndsWith(localName, "-template"));
verify(mockElement, times(1)).getLocalName();
}
protected void assertIsSubRegionWhenElementLocalNameEndsWithRegion(String localName) {
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn(localName);
assertThat(regionParser.isSubRegion(mockElement)).isEqualTo(nullSafeEndsWith(localName, "region"));
verify(mockElement, times(1)).getParentNode();
verify(mockNode, times(1)).getLocalName();
}
protected boolean nullSafeEndsWith(String localName, String suffix) {
return (localName != null && localName.endsWith(suffix));
}
@Test
public void getBeanClassIsEqualToTestRegionFactoryBean() {
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
Element mockElement = mock(Element.class);
doReturn(AbstractRegionParserUnitTests.class).when(regionParserSpy).getRegionFactoryClass();
assertThat(regionParserSpy.getBeanClass(mockElement)).isEqualTo(AbstractRegionParserUnitTests.class);
verify(regionParserSpy, times(1)).getBeanClass(eq(mockElement));
verify(regionParserSpy, times(1)).getRegionFactoryClass();
}
@Test
public void getParentNameWhenTemplateIsSet() {
Element mockElement = mock(Element.class);
when(mockElement.getAttribute(eq("template"))).thenReturn("test");
assertThat(regionParser.getParentName(mockElement)).isEqualTo("test");
verify(mockElement, times(1)).getAttribute(eq("template"));
}
@Test
public void getParentNameWhenTemplateIsUnset() {
Element mockElement = mock(Element.class);
when(mockElement.getAttribute(eq("template"))).thenReturn(null);
assertThat(regionParser.getParentName(mockElement)).isNull();
verify(mockElement, times(1)).getAttribute(eq("template"));
}
@Test
public void isRegionTemplateWithRegionTemplateElementsIsTrue() {
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region-template");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region-template");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region-template");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region-template");
}
@Test
public void isRegionTemplateWithRegionElementsIsFalse() {
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("client-region");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("local-region");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("partitioned-region");
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("replicated-region");
}
@Test
public void isRegionTemplateWhenElementLocalNameDoesNotEndWithTemplateIsFalse() {
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate("disk-store");
}
@Test
public void isRegionTemplateWhenElementLocalNameIsNullIsFalse() {
assertIsRegionTemplateWhenElementLocalNameEndsWithTemplate(null);
}
@Test
public void isSubRegionWithRegionElementIsTrue() {
assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region");
}
@Test
public void isSubRegionWithRegionTemplateElementIsFalse() {
assertIsSubRegionWhenElementLocalNameEndsWithRegion("client-region-template");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("local-region-template");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("partitioned-region-template");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("replicated-region-template");
assertIsSubRegionWhenElementLocalNameEndsWithRegion("region-template");
}
@Test
public void isSubRegionWhenElementLocalNameDoesNotEndWithRegionIsFalse() {
assertIsSubRegionWhenElementLocalNameEndsWithRegion("disk-store");
}
@Test
public void isSubRegionWhenElementLocalNameIsNullIsFalse() {
assertIsSubRegionWhenElementLocalNameEndsWithRegion(null);
}
@Test
public void doParseWithAbstractRegionTemplate() {
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getLocalName()).thenReturn("partitioned-region-template");
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn("cache");
regionParserSpy.doParse(mockElement, null, builder);
assertThat(builder.getRawBeanDefinition().isAbstract()).isTrue();
verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder));
verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class),
eq(builder), eq(false));
}
@Test
public void doParseWithNonAbstractSubRegion() {
AbstractRegionParser regionParserSpy = spy(AbstractRegionParser.class);
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
Element mockElement = mock(Element.class);
Node mockNode = mock(Node.class);
when(mockElement.getLocalName()).thenReturn("replicated-region");
when(mockElement.getParentNode()).thenReturn(mockNode);
when(mockNode.getLocalName()).thenReturn("replicated-region");
regionParserSpy.doParse(mockElement, null, builder);
assertThat(builder.getRawBeanDefinition().isAbstract()).isFalse();
verify(regionParserSpy, times(1)).doParse(eq(mockElement), isNull(ParserContext.class), eq(builder));
verify(regionParserSpy, times(1)).doParseRegion(eq(mockElement), isNull(ParserContext.class),
eq(builder), eq(true));
}
@Test
public void validateDataPolicyShortcutAttributesMutualExclusion() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement, never()).hasAttribute(eq("shortcut"));
}
@Test
public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicy() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(false);
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement).hasAttribute(eq("shortcut"));
}
@Test
public void validateDataPolicyShortcutAttributesMutualExclusionWithShortcut() {
Element mockElement = mock(Element.class);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(false);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, null);
verify(mockElement).hasAttribute(eq("data-policy"));
verify(mockElement, never()).hasAttribute(eq("shortcut"));
}
@Test
public void validateDataPolicyShortcutAttributesMutualExclusionWithDataPolicyAndShortcut() {
Element mockElement = mock(Element.class);
XmlReaderContext mockReaderContext = mock(XmlReaderContext.class);
ParserContext mockParserContext = new ParserContext(mockReaderContext, null);
when(mockElement.hasAttribute(matches("data-policy"))).thenReturn(true);
when(mockElement.hasAttribute(matches("shortcut"))).thenReturn(true);
when(mockElement.getTagName()).thenReturn("local-region");
regionParser.validateDataPolicyShortcutAttributesMutualExclusion(mockElement, mockParserContext);
verify(mockReaderContext).error(
eq("Only one of [data-policy, shortcut] may be specified with element 'local-region'."),
eq(mockElement));
}
protected static class TestRegionParser extends AbstractRegionParser {
@Override
protected Class<?> getRegionFactoryClass() {
return getClass();
}
@Override
protected void doParseRegion(Element element, ParserContext parserContext,
BeanDefinitionBuilder builder, boolean subRegion) {
throw new UnsupportedOperationException("Not Implemented");
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
@@ -27,6 +27,11 @@ import static org.junit.Assert.assertTrue;
import java.util.Properties;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.util.GatewayConflictHelper;
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
import com.gemstone.gemfire.cache.util.TimestampedEntryEvent;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,17 +41,10 @@ import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.data.gemfire.GemfireBeanFactoryLocator;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.data.gemfire.test.GemfireProfileValueSource;
import org.springframework.test.annotation.ProfileValueSourceConfiguration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.util.ReflectionTestUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.util.GatewayConflictHelper;
import com.gemstone.gemfire.cache.util.GatewayConflictResolver;
import com.gemstone.gemfire.cache.util.TimestampedEntryEvent;
/**
* @author Costin Leau
* @author John Blum
@@ -223,5 +221,4 @@ public class CacheNamespaceTest{
throw new UnsupportedOperationException("Not Implemented!");
}
}
}

View File

@@ -14,12 +14,15 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,9 +32,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
/**
* The CacheServerNamespaceTest class is a test suite of test cases testing the functionality of the SDG XML namespace
* when configuring a GemFire Cache Servers and Client Subscription.

View File

@@ -14,12 +14,16 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.SubscriptionAttributes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,13 +33,9 @@ import org.springframework.data.gemfire.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.SubscriptionAttributes;
/**
* Test to ensure subscription policy can be applied to server regions.
*
*
* @author Lyndon Adams
* @author John Blum
* @since 1.3.0
@@ -44,10 +44,10 @@ import com.gemstone.gemfire.cache.SubscriptionAttributes;
@ContextConfiguration("subscription-ns.xml")
@SuppressWarnings("unused")
public class CacheSubscriptionTest{
@Autowired
private ApplicationContext context;
@Test
public void testReplicatedRegionSubscriptionAllPolicy() throws Exception {
assertTrue(context.containsBean("replicALL"));
@@ -77,7 +77,7 @@ public class CacheSubscriptionTest{
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.CACHE_CONTENT, subscriptionAttributes.getInterestPolicy());
}
@Test
public void testPartitionRegionSubscriptionDefaultPolicy() throws Exception {
assertTrue(context.containsBean("partDEFAULT"));
@@ -92,5 +92,5 @@ public class CacheSubscriptionTest{
assertNotNull(subscriptionAttributes);
assertEquals(InterestPolicy.DEFAULT, subscriptionAttributes.getInterestPolicy());
}
}

View File

@@ -14,24 +14,25 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.pdx.PdxSerializer;
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.CacheFactoryBean;
import org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.pdx.PdxSerializer;
/**
* The CacheUsingPdxNamespaceTest class is a test suite of test case testing the Spring Data GemFire XML namespace
* when PDX is configured in GemFire.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -23,6 +23,8 @@ import static org.junit.Assert.assertThat;
import java.util.Properties;
import com.gemstone.gemfire.pdx.PdxSerializer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,8 +33,6 @@ import org.springframework.data.gemfire.client.ClientCacheFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.pdx.PdxSerializer;
/**
* The ClientCacheNamespaceTest class is a test suite of test cases testing the contract and functionality
* of the Spring Data GemFire ClientCacheParser.

View File

@@ -15,13 +15,9 @@
*
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
@@ -43,48 +39,62 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* The ClientCacheParserTest class is a test suite of test cases testing the contract and functionality of the
* ClientCacheParser class.
* Unit tests for {@link ClientCacheParser}.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.data.gemfire.config.xml.ClientCacheParser
* @since 1.8.0
*/
@RunWith(MockitoJUnitRunner.class)
public class ClientCacheParserTest {
public class ClientCacheParserUnitTests {
@Mock
private Element mockElement;
protected void assertPropertyIsPresent(BeanDefinition beanDefinition, String propertyName) {
assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isTrue();
}
protected void assertPropertyIsNotPresent(BeanDefinition beanDefinition, String propertyName) {
assertThat(beanDefinition.getPropertyValues().contains(propertyName)).isFalse();
}
protected void assertPropertyValueEquals(BeanDefinition beanDefinition, String propertyName,
Object expectedPropertyValue) {
assertPropertyIsPresent(beanDefinition, propertyName);
assertThat(beanDefinition.getPropertyValues().getPropertyValue(propertyName).getValue())
.isEqualTo(expectedPropertyValue);
}
@Test
@SuppressWarnings("all")
public void beanClassEqualsClientCacheFactoryBean() {
assertThat((Class<ClientCacheFactoryBean>) new ClientCacheParser().getBeanClass(mockElement),
is(equalTo(ClientCacheFactoryBean.class)));
assertThat(new ClientCacheParser().getBeanClass(mockElement)).isEqualTo(ClientCacheFactoryBean.class);
}
@Test
public void doParseSetsProperties() {
NodeList mockNodeList = mock(NodeList.class);
when(mockNodeList.getLength()).thenReturn(0);
when(mockElement.getAttribute(eq("durable-client-id"))).thenReturn("123");
when(mockElement.getAttribute(eq("durable-client-timeout"))).thenReturn("60");
when(mockElement.getAttribute(eq("keep-alive"))).thenReturn("false");
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool");
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool");
when(mockElement.getAttribute(eq("ready-for-events"))).thenReturn(null);
when(mockElement.getChildNodes()).thenReturn(mockNodeList);
when(mockNodeList.getLength()).thenReturn(0);
BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition();
final BeanDefinitionRegistry mockRegistry = mock(BeanDefinitionRegistry.class);
when(mockRegistry.containsBeanDefinition(anyString())).thenReturn(false);
BeanDefinitionBuilder clientCacheBuilder = BeanDefinitionBuilder.genericBeanDefinition();
ClientCacheParser clientCacheParser = new ClientCacheParser() {
@Override protected BeanDefinitionRegistry getRegistry(ParserContext parserContext) {
return mockRegistry;
@@ -95,16 +105,16 @@ public class ClientCacheParserTest {
BeanDefinition clientCacheBeanDefinition = clientCacheBuilder.getBeanDefinition();
assertThat(clientCacheBeanDefinition, is(notNullValue()));
assertThat(clientCacheBeanDefinition).isNotNull();
PropertyValues propertyValues = clientCacheBeanDefinition.getPropertyValues();
assertThat(propertyValues, is(notNullValue()));
assertThat((String) propertyValues.getPropertyValue("durableClientId").getValue(), is(equalTo("123")));
assertThat((String) propertyValues.getPropertyValue("durableClientTimeout").getValue(), is(equalTo("60")));
assertThat((String) propertyValues.getPropertyValue("keepAlive").getValue(), is(equalTo("false")));
assertThat((String) propertyValues.getPropertyValue("poolName").getValue(), is(equalTo("testPool")));
assertThat(propertyValues.getPropertyValue("readyForEvents"), is(nullValue()));
assertThat(propertyValues).isNotNull();
assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientId", "123");
assertPropertyValueEquals(clientCacheBeanDefinition, "durableClientTimeout", "60");
assertPropertyValueEquals(clientCacheBeanDefinition, "keepAlive", "false");
assertPropertyValueEquals(clientCacheBeanDefinition, "poolName", "TestPool");
assertPropertyIsNotPresent(clientCacheBeanDefinition, "readyForEvents");
verify(mockElement, times(1)).getAttribute(eq("durable-client-id"));
verify(mockElement, times(1)).getAttribute(eq("durable-client-timeout"));
@@ -115,7 +125,7 @@ public class ClientCacheParserTest {
@Test
public void postProcessDynamicRegionSupportParsesPoolName() {
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("testPool");
when(mockElement.getAttribute(eq("pool-name"))).thenReturn("TestPool");
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
@@ -123,12 +133,9 @@ public class ClientCacheParserTest {
BeanDefinition beanDefinition = builder.getBeanDefinition();
assertThat(beanDefinition, is(notNullValue()));
assertThat(beanDefinition.getPropertyValues(), is(notNullValue()));
assertThat(beanDefinition.getPropertyValues().getPropertyValue("poolName"), is(notNullValue()));
assertThat((String) beanDefinition.getPropertyValues().getPropertyValue("poolName").getValue(), is(equalTo("testPool")));
assertThat(beanDefinition).isNotNull();
assertPropertyValueEquals(beanDefinition, "poolName", "TestPool");
verify(mockElement, times(1)).getAttribute(eq("pool-name"));
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -33,22 +33,6 @@ 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.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.CacheLoader;
import com.gemstone.gemfire.cache.CacheLoaderException;
@@ -66,6 +50,22 @@ import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
import com.gemstone.gemfire.compression.Compressor;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
/**
* The ClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of GemFire Client Region namespace support in SDG.
@@ -74,7 +74,7 @@ import com.gemstone.gemfire.compression.Compressor;
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.client.ClientRegionFactoryBean
* @see org.springframework.data.gemfire.config.ClientRegionParser
* @see org.springframework.data.gemfire.config.xml.ClientRegionParser
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="client-ns.xml")
@@ -374,5 +374,4 @@ public class ClientRegionNamespaceTest {
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertTrue;
@@ -35,7 +35,8 @@ public class ClientRegionUsingDataPolicyAndShortcutTest {
@Test(expected = BeanDefinitionParsingException.class)
public void testClientRegionBeanDefinitionWithDataPolicyAndShortcut() {
try {
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/client-region-using-datapolicy-and-shortcut.xml");
new ClassPathXmlApplicationContext(
"/org/springframework/data/gemfire/config/xml/client-region-using-datapolicy-and-shortcut.xml");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("Only one of [data-policy, shortcut] may be specified with element"));

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,8 +26,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.query.CqListener;
import com.gemstone.gemfire.cache.query.CqQuery;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -43,10 +48,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ErrorHandler;
import com.gemstone.gemfire.cache.client.ClientCache;
import com.gemstone.gemfire.cache.query.CqListener;
import com.gemstone.gemfire.cache.query.CqQuery;
/**
* The ContinuousQueryListenerContainerNamespaceTest class is a test suite of test cases testing the SDG XML namespace
* for proper configuration and initialization of a ContinuousQueryListenerContainer bean component

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,6 +26,22 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FilenameFilter;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
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.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Region.Entry;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -43,22 +59,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.FileSystemUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.DiskStoreFactory;
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.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Region.Entry;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.util.ObjectSizer;
/**
* @author Costin Leau
* @author David Turanski
@@ -186,7 +186,7 @@ public class DiskStoreAndEvictionRegionParsingTest {
assertEquals(400, regionTTI.getTimeout());
assertEquals(ExpirationAction.INVALIDATE, regionTTI.getAction());
}
@Test
@SuppressWarnings("rawtypes")
@@ -194,10 +194,10 @@ public class DiskStoreAndEvictionRegionParsingTest {
assertTrue(applicationContext.containsBean("replicated-data-custom-expiry"));
RegionFactoryBean fb = applicationContext.getBean("&replicated-data-custom-expiry", RegionFactoryBean.class);
RegionAttributes attrs = TestUtils.readField("attributes", fb);
assertNotNull(attrs.getCustomEntryIdleTimeout());
assertNotNull(attrs.getCustomEntryTimeToLive());
assertTrue(attrs.getCustomEntryIdleTimeout() instanceof TestCustomExpiry);
assertTrue(attrs.getCustomEntryTimeToLive() instanceof TestCustomExpiry);
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.util.Properties;
import com.gemstone.gemfire.cache.DiskStore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +32,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DiskStore;
/**
* The DiskStoreNamespaceTest class is a test suite of test cases testing the contract and functionality of using
* Spring Data GemFire's XML namespace to configure GemFire Disk Stores.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -23,6 +23,9 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DynamicRegionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,20 +33,17 @@ import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DynamicRegionFactory;
/**
* @author David Turanski
*
*
* This requires a real cache
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("/org/springframework/data/gemfire/config/dynamic-region-ns.xml")
@ContextConfiguration("/org/springframework/data/gemfire/config/xml/dynamic-region-ns.xml")
public class DynamicRegionNamespaceTest {
@Autowired ApplicationContext ctx;
@Test
public void testBasicCache() throws Exception {
DynamicRegionFactory drf = DynamicRegionFactory.get();
@@ -56,4 +56,4 @@ public class DynamicRegionNamespaceTest {
assertFalse(config.registerInterest);
assertEquals(File.separator + "foo", config.diskDir.getPath());
}
}
}

View File

@@ -14,21 +14,21 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import com.gemstone.gemfire.cache.execute.FunctionAdapter;
import com.gemstone.gemfire.cache.execute.FunctionContext;
import com.gemstone.gemfire.cache.execute.FunctionService;
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.execute.FunctionAdapter;
import com.gemstone.gemfire.cache.execute.FunctionContext;
import com.gemstone.gemfire.cache.execute.FunctionService;
/**
* @author Costin Leau
* @author David Turanski

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
@@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverAutoStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
@@ -31,8 +33,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverDefaultStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
@@ -30,8 +32,6 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverManualStartNamespaceTest class is a test suite of test cases testing the contract
* and functionality of Gateway Receiver configuration in Spring Data GemFire using the XML namespace (XSD).

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -27,15 +27,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
@@ -47,6 +38,15 @@ import com.gemstone.gemfire.cache.wan.GatewaySender;
import com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
import org.junit.AfterClass;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.gemfire.RecreatingSpringApplicationContextTest;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.test.GemfireTestBeanPostProcessor;
import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean;
/**
* The GemfireV7GatewayNamespaceTest class is a test suite of test cases testing the GemFire 7.0 WAN functionality
* by configuring various Gateway senders and receivers.
@@ -90,7 +90,7 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
*/
@Override
protected String location() {
return "/org/springframework/data/gemfire/config/gateway-v7-ns.xml";
return "/org/springframework/data/gemfire/config/xml/gateway-v7-ns.xml";
}
@Test
@@ -275,5 +275,4 @@ public class GemfireV7GatewayNamespaceTest extends RecreatingSpringApplicationCo
return false;
}
}
}

View File

@@ -14,13 +14,17 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.EntryEvent;
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -29,10 +33,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.EntryEvent;
import com.gemstone.gemfire.cache.wan.GatewayEventSubstitutionFilter;
import com.gemstone.gemfire.cache.wan.GatewaySender;
/**
* The GemfireV8GatewayNamespaceTest class is a test suite of test cases testing the contract and functionality of
* GemFire 8 Gateway Sender/Receiver support.
@@ -63,7 +63,7 @@ public class GemfireV8GatewayNamespaceTest {
@Test
public void testGatewaySenderEventSubstitutionFilter() {
assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!",
assertNotNull("The 'gatewaySenderEventSubtitutionFilter' bean was not properly configured and initialized!",
gatewaySenderWithEventSubstitutionFilter);
assertEquals("gateway-sender-with-event-substitution-filter", gatewaySenderWithEventSubstitutionFilter.getId());
assertEquals(3, gatewaySenderWithEventSubstitutionFilter.getRemoteDSId());

View File

@@ -14,21 +14,21 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.query.Index;
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.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).
@@ -37,7 +37,7 @@ import com.gemstone.gemfire.cache.query.Index;
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.IndexFactoryBean
* @see org.springframework.data.gemfire.config.IndexParser
* @see org.springframework.data.gemfire.config.xml.IndexParser
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -40,7 +40,8 @@ public class InvalidRegionDefinitionUsingBeansNamespaceTest {
@Test(expected = IllegalArgumentException.class)
public void testInvalidDataPolicyPersistentAttributeSettings() {
try {
new ClassPathXmlApplicationContext("org/springframework/data/gemfire/config/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml");
new ClassPathXmlApplicationContext(
"org/springframework/data/gemfire/config/xml/InvalidDataPolicyPersistentAttributeSettingsBeansNamespaceTest.xml");
}
catch (BeanCreationException expected) {
assertTrue(expected.getCause() instanceof IllegalArgumentException);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertTrue;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -24,6 +24,8 @@ import static org.junit.Assert.fail;
import java.util.List;
import java.util.Map;
import com.gemstone.gemfire.internal.datasource.ConfigProperty;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,8 +34,6 @@ import org.springframework.data.gemfire.CacheFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.internal.datasource.ConfigProperty;
/**
* The JndiBindingsPropertyPlaceholderTest class is a test suite of test cases testing the configuration of a GemFire
* Cache JNDI DataSource using property placeholders.

View File

@@ -14,20 +14,20 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.internal.datasource.GemFireBasicDataSource;
/**
* This test requires a real cache
*

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -23,6 +23,14 @@ import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.compression.Compressor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,14 +44,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.compression.Compressor;
/**
* The LocalRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of GemFire's Local Region support in SDG.
@@ -52,7 +52,7 @@ import com.gemstone.gemfire.compression.Compressor;
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.LocalRegionFactoryBean
* @see org.springframework.data.gemfire.config.LocalRegionParser
* @see org.springframework.data.gemfire.config.xml.LocalRegionParser
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="local-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@@ -60,7 +60,7 @@ public class LocalRegionNamespaceTest {
@Autowired
private ApplicationContext context;
@Test
public void testSimpleLocalRegion() throws Exception {
@@ -150,7 +150,7 @@ public class LocalRegionNamespaceTest {
assertEquals("existing", TestUtils.readField("name", localRegionFactoryBean));
assertSame(existing, context.getBean("lookup"));
}
@Test
@SuppressWarnings("rawtypes")
public void testLocalPersistent() {

View File

@@ -14,24 +14,24 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Scope;
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.EvictionAction;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.Scope;
/**
* The LocalRegionWithEvictionPolicyActionNamespaceTest class is a test suite of tests cases testing the Eviction Policy
* Actions on Local Regions defined in a Spring context configuration file.

View File

@@ -13,12 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.LossAction;
import com.gemstone.gemfire.cache.MembershipAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.ResumptionAction;
import com.gemstone.gemfire.distributed.Role;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,18 +33,12 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.LossAction;
import com.gemstone.gemfire.cache.MembershipAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.ResumptionAction;
import com.gemstone.gemfire.distributed.Role;
/**
* @author David Turanski
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/org/springframework/data/gemfire/config/membership-attributes-ns.xml",
@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/membership-attributes-ns.xml",
initializers=GemfireTestApplicationContextInitializer.class)
public class MembershipAttributesTest {

View File

@@ -1,28 +1,28 @@
/*
* Copyright 2002-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;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.Region;
/**
* @author David Turanski
* @author John Blum
@@ -31,7 +31,7 @@ public class MultipleCacheTest {
@Test
public void testMultipleCaches() {
String configLocation = "/org/springframework/data/gemfire/config/MultipleCacheTest-context.xml";
String configLocation = "/org/springframework/data/gemfire/config/xml/MultipleCacheTest-context.xml";
ConfigurableApplicationContext context1 = new ClassPathXmlApplicationContext(configLocation);
ConfigurableApplicationContext context2 = new ClassPathXmlApplicationContext(configLocation);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -26,6 +26,16 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.FixedPartitionAttributes;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.partition.PartitionListener;
import com.gemstone.gemfire.cache.partition.PartitionListenerAdapter;
import com.gemstone.gemfire.compression.Compressor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,16 +50,6 @@ 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.FixedPartitionAttributes;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.partition.PartitionListener;
import com.gemstone.gemfire.cache.partition.PartitionListenerAdapter;
import com.gemstone.gemfire.compression.Compressor;
/**
* The PartitionRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of the GemFire Partition Region support in SDG.
@@ -58,7 +58,7 @@ import com.gemstone.gemfire.compression.Compressor;
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
* @see org.springframework.data.gemfire.config.PartitionedRegionParser
* @see org.springframework.data.gemfire.config.xml.PartitionedRegionParser
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "partitioned-ns.xml", initializers = GemfireTestApplicationContextInitializer.class)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @see org.junit.Test
* @see org.springframework.data.gemfire.client.PoolAdapter
* @see org.springframework.data.gemfire.client.PoolFactoryBean
* @see org.springframework.data.gemfire.config.PoolParser
* @see org.springframework.data.gemfire.config.xml.PoolParser
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see com.gemstone.gemfire.cache.client.Pool
*/

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
@@ -60,7 +60,7 @@ import org.w3c.dom.NodeList;
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.data.gemfire.config.PoolParser
* @see org.springframework.data.gemfire.config.xml.PoolParser
* @since 1.7.0
*/
@RunWith(MockitoJUnitRunner.class)

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -22,6 +22,11 @@ import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,11 +37,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.PartitionAttributes;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
/**
* The RawRegionBeanDefinitionTest class is a test suite of test cases testing the contract and functionality
* of the SDG RegionFactoryBean class, and specifically the specification of the GemFire Region DataPolicy,

View File

@@ -14,25 +14,25 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
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.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.internal.cache.lru.LRUCapacityController;
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;
/**
* The RegionEvictionAttributesNamespaceTest class is a test suite of test cases testing the use of
* Eviction configuration settings (EvictionAttributes) in the SDG XML namespace.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -23,6 +23,12 @@ import static org.mockito.Mockito.mock;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
@@ -30,12 +36,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
import com.gemstone.gemfire.cache.CustomExpiry;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.ExpirationAction;
import com.gemstone.gemfire.cache.ExpirationAttributes;
import com.gemstone.gemfire.cache.Region;
/**
* The RegionExpirationAttributesNamespaceTest class is a test suite of test cases testing the configuration of
* ExpirationAttribute settings on Region Entries.

View File

@@ -14,23 +14,23 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.InterestPolicy;
import com.gemstone.gemfire.cache.Region;
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

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -81,7 +81,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @link https://jira.springsource.org/browse/SGF-178
* @since 1.3.3
*/
@ContextConfiguration(locations="/org/springframework/data/gemfire/config/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml",
@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/RegionWithSubRegionBeanDefinitionHashCodeTest-context.xml",
initializers=GemfireTestApplicationContextInitializer.class)
@RunWith(SpringJUnit4ClassRunner.class)
@SuppressWarnings("unused")

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -22,16 +22,16 @@ import static org.junit.Assert.assertNull;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.Region;
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.EvictionAction;
import com.gemstone.gemfire.cache.Region;
/**
* The RegionsWithDiskStoreAndPersistenceEvictionSettingsTest class is a test suite testing the functionality
* of GemFire Cache Regions when persistent/non-persistent with and without Eviction settings when specifying a
@@ -60,7 +60,7 @@ public class RegionsWithDiskStoreAndPersistenceEvictionSettingsTest {
@Test
public void testNotPersistentNoOverflowRegion() {
assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!",
assertNotNull("The Not Persistent, No Overflow Region was not properly configured and initialized!",
notPersistentNoOverflowRegion);
assertNotNull(notPersistentNoOverflowRegion.getAttributes());

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -24,6 +24,14 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.compression.Compressor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,14 +46,6 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.ObjectUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.compression.Compressor;
/**
* The ReplicatedRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of GemFire Replicated Region support in SDG.
@@ -54,7 +54,7 @@ import com.gemstone.gemfire.compression.Compressor;
* @author David Turanski
* @author John Blum
* @see org.springframework.data.gemfire.ReplicatedRegionFactoryBean
* @see org.springframework.data.gemfire.config.ReplicatedRegionParser
* @see org.springframework.data.gemfire.config.xml.ReplicatedRegionParser
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="replicated-ns.xml", initializers=GemfireTestApplicationContextInitializer.class)
@@ -217,5 +217,4 @@ public class ReplicatedRegionNamespaceTest {
return this.name;
}
}
}

View File

@@ -14,12 +14,16 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheLoader;
import com.gemstone.gemfire.cache.Region;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,10 +34,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheLoader;
import com.gemstone.gemfire.cache.Region;
/**
* The SubRegionNamespaceTest class is a test suite of test cases testing the contract and functionality of
* Region/SubRegion creation in a GemFire Cache.

View File

@@ -14,14 +14,21 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,12 +37,6 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent;
import com.gemstone.gemfire.cache.asyncqueue.AsyncEventListener;
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
/**
* The SubRegionSubElementNamespaceTest class...
*
@@ -114,5 +115,4 @@ public class SubRegionSubElementNamespaceTest {
public void close() {
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -40,7 +40,8 @@ public class SubRegionWithInvalidDataPolicyTest {
@Test(expected = XmlBeanDefinitionStoreException.class)
public void testSubRegionBeanDefinitionWithInconsistentDataPolicy() {
try {
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/subregion-with-invalid-datapolicy.xml");
new ClassPathXmlApplicationContext(
"/org/springframework/data/gemfire/config/xml/subregion-with-invalid-datapolicy.xml");
}
catch (XmlBeanDefinitionStoreException expected) {
//expected.printStackTrace(System.err);
@@ -53,7 +54,8 @@ public class SubRegionWithInvalidDataPolicyTest {
@Test(expected = BeanCreationException.class)
public void testSubRegionBeanDefinitionWithInvalidDataPolicyPersistentSettings() {
try {
new ClassPathXmlApplicationContext("/org/springframework/data/gemfire/config/subregion-with-inconsistent-datapolicy-persistent-settings.xml");
new ClassPathXmlApplicationContext(
"/org/springframework/data/gemfire/config/xml/subregion-with-inconsistent-datapolicy-persistent-settings.xml");
}
catch (BeanCreationException expected) {
//expected.printStackTrace(System.err);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -24,13 +24,8 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeNotNull;
import java.util.Arrays;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.CacheLoader;
@@ -47,6 +42,12 @@ import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StringUtils;
/**
* The TemplateClientRegionNamespaceTest class is a test suite of test cases testing the contract and functionality
* of Client Region Templates using Spring Data GemFire XML namespace configuration meta-data.

View File

@@ -14,14 +14,23 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.EntryOperation;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.PartitionResolver;
import com.gemstone.gemfire.cache.Region;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,14 +40,6 @@ import org.springframework.data.gemfire.test.support.FileSystemUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.DiskStore;
import com.gemstone.gemfire.cache.EntryOperation;
import com.gemstone.gemfire.cache.EvictionAction;
import com.gemstone.gemfire.cache.EvictionAlgorithm;
import com.gemstone.gemfire.cache.PartitionResolver;
import com.gemstone.gemfire.cache.Region;
/**
* The PersistentPartitionRegionTemplateTest class is a test suite of test cases testing the functionality of
* Spring Data GemFire's Region templates with a 'persistent', PARTITION Region configuration.

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertTrue;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -27,19 +27,8 @@ import static org.junit.Assume.assumeNotNull;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanIsAbstractException;
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 org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.CacheListener;
import com.gemstone.gemfire.cache.CacheLoader;
@@ -69,6 +58,18 @@ import com.gemstone.gemfire.cache.util.CacheWriterAdapter;
import com.gemstone.gemfire.cache.util.ObjectSizer;
import com.gemstone.gemfire.distributed.Role;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanIsAbstractException;
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 org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
/**
* The TemplateRegionsNamespaceTests class is a test suite of test cases testing the functionality and support for
* Region Templating in Spring Data GemFire.

View File

@@ -13,13 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import javax.annotation.Resource;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.TransactionEvent;
import com.gemstone.gemfire.cache.TransactionListener;
import com.gemstone.gemfire.cache.TransactionWriter;
import com.gemstone.gemfire.cache.TransactionWriterException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanNameAware;
@@ -28,20 +34,15 @@ import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitia
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.TransactionEvent;
import com.gemstone.gemfire.cache.TransactionListener;
import com.gemstone.gemfire.cache.TransactionWriter;
import com.gemstone.gemfire.cache.TransactionWriterException;
/**
* @author David Turanski
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="tx-listeners-and-writers.xml",
initializers=GemfireTestApplicationContextInitializer.class)
initializers=GemfireTestApplicationContextInitializer.class)
public class TxEventHandlersTest {
@Autowired
TestListener txListener1;
@@ -54,16 +55,14 @@ public class TxEventHandlersTest {
@Resource(name = "gemfireCache")
Cache cache;
@Test
public void test() throws Exception {
TransactionListener[] listeners = cache.getCacheTransactionManager().getListeners();
assertEquals(2,listeners.length);
assertSame(txListener1,listeners[0]);
assertSame(txListener2,listeners[1]);
assertSame(txWriter,cache.getCacheTransactionManager().getWriter());
assertEquals(2, listeners.length);
assertSame(txListener1, listeners[0]);
assertSame(txListener2, listeners[1]);
assertSame(txWriter, cache.getCacheTransactionManager().getWriter());
}
public static class TestListener implements TransactionListener, BeanNameAware {
@@ -90,14 +89,10 @@ public class TxEventHandlersTest {
@Override
public void afterFailedCommit(TransactionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterRollback(TransactionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
@@ -114,8 +109,6 @@ public class TxEventHandlersTest {
@Override
public void close() {
// TODO Auto-generated method stub
}
@Override

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
package org.springframework.data.gemfire.config.xml;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -32,7 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Costin Leau
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="/org/springframework/data/gemfire/config/tx-ns.xml",
@ContextConfiguration(locations= "/org/springframework/data/gemfire/config/xml/tx-ns.xml",
initializers=GemfireTestApplicationContextInitializer.class)
public class TxManagerNamespaceTest {
@@ -43,8 +43,8 @@ public class TxManagerNamespaceTest {
assertTrue(ctx.containsBean("gemfireTransactionManager"));
//Check old style alias also registered
assertTrue(ctx.containsBean("gemfire-transaction-manager"));
GemfireTransactionManager tx = ctx.getBean("gemfireTransactionManager", GemfireTransactionManager.class);
assertFalse(tx.isCopyOnRead());
}
}
}

View File

@@ -36,7 +36,7 @@ import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
/**
* The ServerBasedExecutionBeanDefinitionBuilderTest class is test suite of test cases testing the contract

View File

@@ -43,7 +43,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.data.gemfire.GemfireUtils;
import org.springframework.data.gemfire.TestUtils;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import com.gemstone.gemfire.cache.RegionService;
import com.gemstone.gemfire.cache.client.Pool;

View File

@@ -1,87 +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.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Test;
/**
* The SubscriptionEvictionPolicyConverterTest class is a test suite of test cases testing the contract
* and functionality of the SubscriptionEvictionPolicyConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter
* @since 1.6.0
*/
public class SubscriptionEvictionPolicyConverterTest {
private final SubscriptionEvictionPolicyConverter converter = new SubscriptionEvictionPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.convert("EnTry"));
assertEquals(SubscriptionEvictionPolicy.MEM, converter.convert("MEM"));
assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("nONE"));
assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("NOne"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.setAsText("memory");
}
catch (IllegalArgumentException expected) {
assertEquals("(memory) is not a valid SubscriptionEvictionPolicy!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
assertNull(converter.getValue());
converter.setAsText("enTRY");
assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.getValue());
converter.setAsText("MEm");
assertEquals(SubscriptionEvictionPolicy.MEM, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("KEYS");
}
catch (IllegalArgumentException expected) {
assertEquals("(KEYS) is not a valid SubscriptionEvictionPolicy!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* 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.server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link SubscriptionEvictionPolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter
* @since 1.6.0
*/
public class SubscriptionEvictionPolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final SubscriptionEvictionPolicyConverter converter = new SubscriptionEvictionPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("EnTry")).isEqualTo(SubscriptionEvictionPolicy.ENTRY);
assertThat(converter.convert("MEM")).isEqualTo(SubscriptionEvictionPolicy.MEM);
assertThat(converter.convert("nONE")).isEqualTo(SubscriptionEvictionPolicy.NONE);
assertThat(converter.convert("NOne")).isEqualTo(SubscriptionEvictionPolicy.NONE);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[memory] is not a valid SubscriptionEvictionPolicy");
converter.setAsText("memory");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("enTRY");
assertThat(converter.getValue()).isEqualTo(SubscriptionEvictionPolicy.ENTRY);
converter.setAsText("MEm");
assertThat(converter.getValue()).isEqualTo(SubscriptionEvictionPolicy.MEM);
}
@Test
public void setAsTextWithIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[KEYS] is not a valid SubscriptionEvictionPolicy");
converter.setAsText("KEYS");
}
}

View File

@@ -40,7 +40,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.LazyWiringDeclarableSupport;
import org.springframework.data.gemfire.config.GemfireConstants;
import org.springframework.data.gemfire.config.xml.GemfireConstants;
import org.springframework.data.gemfire.repository.sample.User;
import org.springframework.data.gemfire.support.sample.TestUserDao;
import org.springframework.data.gemfire.support.sample.TestUserService;

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-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.
@@ -20,25 +20,30 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.StringUtils;
/**
* Spring {@link ApplicationContextInitializer} used to configure the Spring Data GemFire test suite
* with mocking enabled or disabled.
*
* @author David Turanski
* @author John Blum
* @see org.springframework.context.ApplicationContextInitializer
* @see org.springframework.context.ConfigurableApplicationContext
*/
public class GemfireTestApplicationContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final Log LOG = LogFactory.getLog(GemfireTestApplicationContextInitializer.class);
public static final String GEMFIRE_TEST_RUNNER_DISABLED =
"org.springframework.data.gemfire.test.GemfireTestRunner.nomock";
public static final String GEMFIRE_TEST_RUNNER_DISABLED = "org.springframework.data.gemfire.test.GemfireTestRunner.nomock";
protected final Log log = LogFactory.getLog(getClass());
/*
* (non-Javadoc)
* @see org.springframework.context.ApplicationContextInitializer#initialize(org.springframework.context.ConfigurableApplicationContext)
/**
* {@inheritDoc}
*/
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
String gemfireTestRunnerDisabled = System.getProperty(GEMFIRE_TEST_RUNNER_DISABLED, Boolean.FALSE.toString());
if (isGemFireTestRunnerDisable(gemfireTestRunnerDisabled)) {
LOG.warn(String.format("WARNING - Mocks disabled; Using real GemFire components (%1$s = %2$s)",
if (isGemFireTestRunnerDisabled(gemfireTestRunnerDisabled)) {
log.warn(String.format("WARNING - Mocks disabled; Using real GemFire components (%1$s = %2$s)",
GEMFIRE_TEST_RUNNER_DISABLED, gemfireTestRunnerDisabled));
}
else {
@@ -46,10 +51,10 @@ public class GemfireTestApplicationContextInitializer implements ApplicationCont
}
}
private boolean isGemFireTestRunnerDisable(final String systemPropertyValue) {
/* (non-Javadoc) */
private boolean isGemFireTestRunnerDisabled(String systemPropertyValue) {
return (Boolean.valueOf(StringUtils.trimAllWhitespace(systemPropertyValue))
|| "yes".equalsIgnoreCase(systemPropertyValue)
|| "y".equalsIgnoreCase(systemPropertyValue));
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright 2012 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.test.model;
/**
* The Gender enum is a enumeration of genders.
*
* @author John Blum
* @since 1.9.0
*/
public enum Gender {
FEMALE,
MALE
}

View File

@@ -0,0 +1,164 @@
/*
* Copyright 2012 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.test.model;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.gemfire.mapping.Region;
import org.springframework.data.gemfire.test.support.IdentifierSequence;
import org.springframework.data.gemfire.util.SpringUtils;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* The Person class...
*
* @author John Blum
* @since 1.0.0
*/
@Region("People")
@SuppressWarnings("unused")
public class Person implements Serializable {
protected static final String BIRTH_DATE_PATTERN = "yyyy/MM/dd";
private Date birthDate;
private Gender gender;
@Id
private Long id;
private final String firstName;
private final String lastName;
public static Date newBirthDate(int year, int month, int dayOfMonth) {
Calendar birthDate = Calendar.getInstance();
birthDate.clear();
birthDate.set(Calendar.YEAR, year);
birthDate.set(Calendar.MONTH, month);
birthDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
return birthDate.getTime();
}
public static Person newPerson(String firstName, String lastName, Date birthDate, Gender gender) {
return newPerson(IdentifierSequence.nextId(), firstName, lastName, birthDate, gender);
}
public static Person newPerson(Long id, String firstName, String lastName, Date birthDate, Gender gender) {
return new Person(id, firstName, lastName, birthDate, gender);
}
@PersistenceConstructor
public Person(String firstName, String lastName, Date birthDate, Gender gender) {
Assert.hasText(firstName, "firstName must be specified");
Assert.hasText(lastName, "lastName must be specified");
this.firstName = firstName;
this.lastName = lastName;
this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null);
this.gender = gender;
}
public Person(Long id, String firstName, String lastName, Date birthDate, Gender gender) {
this(firstName, lastName, birthDate, gender);
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = (birthDate != null ? (Date) birthDate.clone() : null);
}
public String getFirstName() {
return firstName;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public String getLastName() {
return lastName;
}
public String getName() {
return String.format("%1$s %2$s", getFirstName(), getLastName());
}
@Override
public boolean equals(final Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof Person)) {
return false;
}
Person that = (Person) obj;
return SpringUtils.equalsIgnoreNull(this.getId(), that.getId())
&& (ObjectUtils.nullSafeEquals(this.getBirthDate(), that.getBirthDate()))
&& (ObjectUtils.nullSafeEquals(this.getFirstName(), that.getFirstName())
&& (ObjectUtils.nullSafeEquals(this.getGender(), that.getGender()))
&& (ObjectUtils.nullSafeEquals(this.getLastName(), that.getLastName())));
}
@Override
public int hashCode() {
int hashValue = 17;
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getId());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getBirthDate());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getFirstName());
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(getLastName());
return hashValue;
}
protected static String toString(Date dateTime, String DATE_FORMAT_PATTERN) {
return (dateTime == null ? null : new SimpleDateFormat(DATE_FORMAT_PATTERN).format(dateTime));
}
@Override
public String toString() {
return String.format(
"{ @type = %1$s, id = %2$d, firstName = %3$s, lastName = %4$s, birthDate = %5$s, gender = %6$s}",
getClass().getName(), getId(), getFirstName(), getLastName(),
toString(getBirthDate(), BIRTH_DATE_PATTERN), getGender());
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2012 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.test.support;
import java.util.Arrays;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.mockito.internal.matchers.VarargMatcher;
import org.springframework.data.gemfire.util.ArrayUtils;
/**
* MockitoMatchers is a utility class encapsulating customer Hamcrest {@link Matcher Matchers} used by Mockito
* in the Spring Data GemFire project test suite.
*
* @author John Blum
* @see org.hamcrest.Matcher
* @since 1.9.0
*/
public abstract class MockitoMatchers {
/* (non-Javadoc) */
public static Matcher<String> stringArrayMatcher(String... expected) {
return new ArrayMatcher<String>(expected);
}
/* (non-Javadoc) */
protected static final class ArrayMatcher<T> extends BaseMatcher<T> implements VarargMatcher {
private final T[] expected;
protected ArrayMatcher(T... expected) {
this.expected = expected;
}
@Override
public boolean matches(Object item) {
Object[] actual = (item instanceof Object[] ? (Object[]) item : ArrayUtils.asArray(item));
return Arrays.equals(actual, expected);
}
@Override
public void describeTo(Description description) {
description.appendText(String.format("expected [%1$s]", this.expected));
}
}
}

View File

@@ -107,26 +107,26 @@ public class ArrayUtilsUnitTests {
@Test
public void isEmptyIsFalse() {
assertThat(ArrayUtils.isEmpty("test", "testing", "tested")).isFalse();
assertThat(ArrayUtils.isEmpty("test")).isFalse();
assertThat(ArrayUtils.isEmpty("")).isFalse();
assertThat(ArrayUtils.isEmpty(null, null, null)).isFalse();
assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray("test", "testing", "tested"))).isFalse();
assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray("test"))).isFalse();
assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray(""))).isFalse();
assertThat(ArrayUtils.isEmpty(ArrayUtils.asArray(null, null, null))).isFalse();
}
@Test
public void isEmptyIsTrue() {
assertThat(ArrayUtils.isEmpty()).isTrue();
assertThat(ArrayUtils.isEmpty((Object[]) null)).isTrue();
assertThat(ArrayUtils.isEmpty(new Object[0])).isTrue();
assertThat(ArrayUtils.isEmpty(null)).isTrue();
}
@Test
public void length() {
assertThat(ArrayUtils.length("test", "testing", "tested")).isEqualTo(3);
assertThat(ArrayUtils.length("test")).isEqualTo(1);
assertThat(ArrayUtils.length("")).isEqualTo(1);
assertThat(ArrayUtils.length(null, null, null)).isEqualTo(3);
assertThat(ArrayUtils.length()).isEqualTo(0);
assertThat(ArrayUtils.length((Object[]) null)).isEqualTo(0);
assertThat(ArrayUtils.length(ArrayUtils.asArray("test", "testing", "tested"))).isEqualTo(3);
assertThat(ArrayUtils.length(ArrayUtils.asArray("test"))).isEqualTo(1);
assertThat(ArrayUtils.length(ArrayUtils.asArray(""))).isEqualTo(1);
assertThat(ArrayUtils.length(ArrayUtils.asArray(null, null, null))).isEqualTo(3);
assertThat(ArrayUtils.length(new Object[0])).isEqualTo(0);
assertThat(ArrayUtils.length(null)).isEqualTo(0);
}
@Test

View File

@@ -0,0 +1,129 @@
/*
* Copyright 2012 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.util;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.data.gemfire.test.support.MockitoMatchers;
/**
* Unit tests for {@link SpringUtils}.
*
* @author John Blum
* @see org.junit.Test
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.springframework.data.gemfire.util.SpringUtils
* @since 1.9.0
*/
@RunWith(MockitoJUnitRunner.class)
public class SpringUtilsUnitTests {
@Mock
private BeanDefinition mockBeanDefinition;
@Test
public void addDependsOnToExistingDependencies() {
when(mockBeanDefinition.getDependsOn()).thenReturn(ArrayUtils.asArray("testBeanNameOne", "testBeanNameTwo"));
assertThat(SpringUtils.addDependsOn(mockBeanDefinition, "testBeanNameThree")).isSameAs(mockBeanDefinition);
verify(mockBeanDefinition, times(1)).getDependsOn();
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(
MockitoMatchers.stringArrayMatcher("testBeanNameOne", "testBeanNameTwo", "testBeanNameThree")));
}
@Test
public void addDependsOnToNonExistingDependencies() {
when(mockBeanDefinition.getDependsOn()).thenReturn(null);
assertThat(SpringUtils.addDependsOn(mockBeanDefinition, "testBeanName")).isSameAs(mockBeanDefinition);
verify(mockBeanDefinition, times(1)).getDependsOn();
verify(mockBeanDefinition, times(1)).setDependsOn(argThat(MockitoMatchers.stringArrayMatcher("testBeanName")));
}
@Test
public void defaultIfEmptyReturnsValue() {
assertThat(SpringUtils.defaultIfEmpty("test", "DEFAULT")).isEqualTo("test");
assertThat(SpringUtils.defaultIfEmpty("abc123", "DEFAULT")).isEqualTo("abc123");
assertThat(SpringUtils.defaultIfEmpty("123", "DEFAULT")).isEqualTo("123");
assertThat(SpringUtils.defaultIfEmpty("X", "DEFAULT")).isEqualTo("X");
assertThat(SpringUtils.defaultIfEmpty("$", "DEFAULT")).isEqualTo("$");
assertThat(SpringUtils.defaultIfEmpty("_", "DEFAULT")).isEqualTo("_");
assertThat(SpringUtils.defaultIfEmpty("nil", "DEFAULT")).isEqualTo("nil");
assertThat(SpringUtils.defaultIfEmpty("null", "DEFAULT")).isEqualTo("null");
}
@Test
public void defaultIfEmptyReturnsDefault() {
assertThat(SpringUtils.defaultIfEmpty(" ", "DEFAULT")).isEqualTo("DEFAULT");
assertThat(SpringUtils.defaultIfEmpty("", "DEFAULT")).isEqualTo("DEFAULT");
assertThat(SpringUtils.defaultIfEmpty(null, "DEFAULT")).isEqualTo("DEFAULT");
}
@Test
public void defaultIfNullReturnsValue() {
assertThat(SpringUtils.defaultIfNull(true, false)).isTrue();
assertThat(SpringUtils.defaultIfNull('x', 'A')).isEqualTo('x');
assertThat(SpringUtils.defaultIfNull(1, 2)).isEqualTo(1);
assertThat(SpringUtils.defaultIfNull(Math.PI, 2.0d)).isEqualTo(Math.PI);
assertThat(SpringUtils.defaultIfNull("test", "DEFAULT")).isEqualTo("test");
}
@Test
public void defaultIfNullReturnsDefault() {
assertThat(SpringUtils.defaultIfNull(null, false)).isFalse();
assertThat(SpringUtils.defaultIfNull(null, 'A')).isEqualTo('A');
assertThat(SpringUtils.defaultIfNull(null, 2)).isEqualTo(2);
assertThat(SpringUtils.defaultIfNull(null, 2.0d)).isEqualTo(2.0d);
assertThat(SpringUtils.defaultIfNull(null, "DEFAULT")).isEqualTo("DEFAULT");
}
@Test
public void equalsIgnoreNullIsTrue() {
assertThat(SpringUtils.equalsIgnoreNull(null, null)).isTrue();
assertThat(SpringUtils.equalsIgnoreNull(true, true)).isTrue();
assertThat(SpringUtils.equalsIgnoreNull('x', 'x')).isTrue();
assertThat(SpringUtils.equalsIgnoreNull(1, 1)).isTrue();
assertThat(SpringUtils.equalsIgnoreNull(Math.PI, Math.PI)).isTrue();
assertThat(SpringUtils.equalsIgnoreNull("null", "null")).isTrue();
assertThat(SpringUtils.equalsIgnoreNull("test", "test")).isTrue();
}
@Test
public void equalsIgnoreNullIsFalse() {
assertThat(SpringUtils.equalsIgnoreNull(null, "null")).isFalse();
assertThat(SpringUtils.equalsIgnoreNull(true, false)).isFalse();
assertThat(SpringUtils.equalsIgnoreNull('x', 'X')).isFalse();
assertThat(SpringUtils.equalsIgnoreNull(1, 2)).isFalse();
assertThat(SpringUtils.equalsIgnoreNull(3.14159d, Math.PI)).isFalse();
assertThat(SpringUtils.equalsIgnoreNull("nil", "null")).isFalse();
}
@Test
public void dereferenceBean() {
assertThat(SpringUtils.dereferenceBean("example")).isEqualTo("&example");
}
}

View File

@@ -26,13 +26,13 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.springframework.data.gemfire.TestUtils;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import com.gemstone.gemfire.cache.wan.GatewaySenderFactory;
import org.junit.Test;
import org.springframework.data.gemfire.TestUtils;
/**
* The GatewaySenderFactoryBeanTest class is a test suite of test cases testing the contract and functionality of the
* GatewaySenderFactoryBean class.
@@ -278,10 +278,9 @@ public class GatewaySenderFactoryBeanTest {
.setOrderPolicy("invalid");
}
catch (IllegalArgumentException expected) {
assertEquals(String.format("(invalid) is not a valid %1$s!", GatewaySender.OrderPolicy.class.getSimpleName()),
assertEquals(String.format("[invalid] is not a valid %s", GatewaySender.OrderPolicy.class.getSimpleName()),
expected.getMessage());
throw expected;
}
}
}

View File

@@ -1,88 +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.wan;
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.wan.GatewaySender;
/**
* The OrderPolicyConverterTest class is a test suite of test cases testing the contract and functionality
* of the OrderPolicyConverter.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.wan.OrderPolicyConverter
* @see com.gemstone.gemfire.cache.wan.GatewaySender.OrderPolicy
* @since 1.7.0
*/
@SuppressWarnings("deprecation")
public class OrderPolicyConverterTest {
private final OrderPolicyConverter converter = new OrderPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(GatewaySender.OrderPolicy.KEY, converter.convert("key"));
assertEquals(GatewaySender.OrderPolicy.PARTITION, converter.convert("Partition"));
assertEquals(GatewaySender.OrderPolicy.THREAD, converter.convert("THREAD"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.convert("process");
}
catch (IllegalArgumentException expected) {
assertEquals("(process) is not a valid OrderPolicy!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
converter.setAsText("PartItIOn");
assertEquals(GatewaySender.OrderPolicy.PARTITION, converter.getValue());
converter.setAsText("thREAD");
assertEquals(GatewaySender.OrderPolicy.THREAD, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("value");
}
catch (IllegalArgumentException expected) {
assertEquals("(value) is not a valid OrderPolicy!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,84 @@
/*
* 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.wan;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
/**
* Unit tests for {@link OrderPolicyConverter}.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.wan.OrderPolicyConverter
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
* @since 1.7.0
*/
public class OrderPolicyConverterUnitTests {
@Rule
public ExpectedException exception = ExpectedException.none();
private final OrderPolicyConverter converter = new OrderPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void convert() {
assertThat(converter.convert("key")).isEqualTo(GatewaySender.OrderPolicy.KEY);
assertThat(converter.convert("Partition")).isEqualTo(GatewaySender.OrderPolicy.PARTITION);
assertThat(converter.convert("THREAD")).isEqualTo(GatewaySender.OrderPolicy.THREAD);
}
@Test
public void convertIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[process] is not a valid OrderPolicy");
converter.convert("process");
}
@Test
public void setAsText() {
assertThat(converter.getValue()).isNull();
converter.setAsText("PartItIOn");
assertThat(converter.getValue()).isEqualTo(GatewaySender.OrderPolicy.PARTITION);
converter.setAsText("thREAD");
assertThat(converter.getValue()).isEqualTo(GatewaySender.OrderPolicy.THREAD);
}
@Test
public void setAsTextWithIllegalValue() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("[value] is not a valid OrderPolicy");
converter.setAsText("value");
}
}