Replace RegionPopulator with STDG's RegionDataInitializingPostProcesor.

This commit is contained in:
John Blum
2021-09-27 11:24:43 -07:00
parent 02e1a14f9e
commit 9ed795cdef
3 changed files with 20 additions and 47 deletions

View File

@@ -19,10 +19,14 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.fork.ServerProcess;
import org.springframework.data.gemfire.repository.GemfireRepository;
import org.springframework.data.gemfire.repository.sample.Person;
import org.springframework.data.gemfire.repository.sample.PersonRepository;
import org.springframework.data.gemfire.tests.integration.ForkingClientServerIntegrationTestsSupport;
import org.springframework.data.gemfire.tests.objects.geode.cache.RegionDataInitializingPostProcessor;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -40,7 +44,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* @see org.springframework.test.context.junit4.SpringRunner
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@ContextConfiguration(locations = "ClientRegionNamespaceRepositoryIntegrationTests-context.xml")
@SuppressWarnings("unused")
public class ClientRegionNamespaceRepositoryIntegrationTests extends ForkingClientServerIntegrationTestsSupport {
@@ -59,4 +63,17 @@ public class ClientRegionNamespaceRepositoryIntegrationTests extends ForkingClie
assertThat(this.repository.count()).isEqualTo(2);
assertThat(this.repository.findAll()).hasSize(2);
}
@Configuration
static class TestConfiguration {
@Bean
RegionDataInitializingPostProcessor<Person> peopleRegionDataInitializer() {
return RegionDataInitializingPostProcessor.<Person>withRegion("simple")
.useAsEntityIdentifier(Person::getId)
.store(new Person(1L, "First1", "Last1"))
.store(new Person(2L, "First2", "Last2"));
}
}
}

View File

@@ -1,43 +0,0 @@
/*
* Copyright 2002-2021 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
*
* https://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.repository.sample;
import javax.annotation.Resource;
import org.apache.geode.cache.Region;
import org.springframework.beans.factory.InitializingBean;
/**
* @author David Turanski
*
*/
public class RegionPopulator implements InitializingBean {
@Resource(name="region")
Region<Object,Object> region;
/* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
public void afterPropertiesSet() throws Exception {
region.put(1L,new Person(1L,"first1", "last1"));
region.put(2L,new Person(2L,"first2", "last2"));
}
public void setRegion(Region<Object,Object> region) {
this.region=region;
}
}

View File

@@ -11,6 +11,7 @@
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd
">
<context:annotation-config/>
<context:property-placeholder/>
<util:properties id="gemfireProperties">
@@ -24,8 +25,6 @@
<gfe:replicated-region id="People" name="simple"/>
<bean class="org.springframework.data.gemfire.repository.sample.RegionPopulator">
<property name="region" ref="People"/>
</bean>
<bean class="org.springframework.data.gemfire.repository.config.ClientRegionNamespaceRepositoryIntegrationTests$TestConfiguration"/>
</beans>