Improve configuration logic.

Edit Javadoc.

Rename memberNameIsCorrect() test case method to memberNameWasConfiguredCorrectly().
This commit is contained in:
John Blum
2018-06-04 18:33:31 -07:00
parent 9b9efe6db2
commit 636289aeef
3 changed files with 26 additions and 14 deletions

View File

@@ -33,10 +33,10 @@ import org.springframework.data.gemfire.config.annotation.support.AbstractAnnota
import org.springframework.util.StringUtils;
/**
* The {@link MemberNameConfiguration} class is a Spring {@link Configuration} class used to set
* an Apache Geode or Pivotal GemFire's name in the distributed system, whether the member
* is a {@link ClientCache client} in the client/server topology or a {@link Cache peer} member
* of the cluster.
* The {@link MemberNameConfiguration} class is a Spring {@link Configuration} class used to configure
* an Apache Geode or Pivotal GemFire's member name in the distributed system, whether the member
* is a {@link ClientCache client} in the client/server topology or a {@link Cache peer} in a cluster
* using the P2P topology.
*
* @author John Blum
* @see org.apache.geode.cache.Cache
@@ -44,6 +44,9 @@ import org.springframework.util.StringUtils;
* @see org.springframework.context.annotation.Bean
* @see org.springframework.context.annotation.Configuration
* @see org.springframework.context.annotation.ImportAware
* @see org.springframework.core.annotation.AnnotationAttributes
* @see org.springframework.core.type.AnnotationMetadata
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.data.gemfire.config.annotation.ClientCacheConfigurer
* @see org.springframework.data.gemfire.config.annotation.PeerCacheConfigurer
* @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport
@@ -64,26 +67,26 @@ public class MemberNameConfiguration extends AbstractAnnotationConfigSupport imp
}
@Override
@SuppressWarnings("all")
public void setImportMetadata(AnnotationMetadata importMetadata) {
if (isAnnotationPresent(importMetadata)) {
AnnotationAttributes memberNameAttributes = getAnnotationAttributes(importMetadata);
setMemberNameIfNotSet(memberNameAttributes.containsKey("name")
? memberNameAttributes.getString("name") : null);
setMemberNameIfNotSet(memberNameAttributes.containsKey("value")
setMemberName(memberNameAttributes.containsKey("value")
? memberNameAttributes.getString("value") : null);
setMemberName(memberNameAttributes.containsKey("name")
? memberNameAttributes.getString("name") : null);
}
}
protected void setMemberName(String memberName) {
this.memberName = memberName;
}
protected void setMemberNameIfNotSet(String memberName) {
setMemberName(this.memberName != null ? this.memberName : memberName);
this.memberName = Optional.ofNullable(memberName)
.filter(StringUtils::hasText)
.orElse(this.memberName);
}
protected Optional<String> getMemberName() {

View File

@@ -31,12 +31,17 @@ import org.springframework.core.annotation.AliasFor;
/**
* The {@link UseMemberName} annotation configures the {@literal name} of the member in the Apache Geode
* or Pivotal GemFire distributed system, whether the member is a {@link ClientCache client} in
* the client/server topology or a {@link Cache peer} member of the cluster.
* the client/server topology or a {@link Cache peer Cache member} in the cluster using the P2P topology.
*
* @author John Blum
* @see java.lang.annotation.Documented
* @see java.lang.annotation.Inherited
* @see java.lang.annotation.Retention
* @see java.lang.annotation.Target
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.client.ClientCache
* @see org.springframework.context.annotation.Import
* @see org.springframework.core.annotation.AliasFor
* @see org.springframework.geode.config.annotation.MemberNameConfiguration
* @since 1.0.0
*/
@@ -49,6 +54,7 @@ public @interface UseMemberName {
/**
* {@link String Name} used for the Apache Geode/Pivotal GemFire distributed system member.
*
* @see #name()
*/
@AliasFor("name")
@@ -56,6 +62,7 @@ public @interface UseMemberName {
/**
* Alias for the {@link String name} of the Apache Geode/Pivotal GemFire distributed system member.
*
* @see #value()
*/
@AliasFor("value")

View File

@@ -32,7 +32,9 @@ import org.springframework.test.context.junit4.SpringRunner;
* Integration tests for {@link UseMemberName} and {@link MemberNameConfiguration}.
*
* @author John Blum
* @see org.apache.geode.cache.GemFireCache
* @see org.springframework.data.gemfire.config.annotation.ClientCacheApplication
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.data.gemfire.tests.mock.annotation.EnableGemFireMockObjects
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
@@ -47,7 +49,7 @@ public class MemberNameConfigurationIntegrationTests extends IntegrationTestsSup
private GemFireCache gemfireCache;
@Test
public void memberNameIsCorrect() {
public void memberNameWasConfiguredCorrectly() {
assertThat(this.gemfireCache).isNotNull();
assertThat(this.gemfireCache.getDistributedSystem()).isNotNull();