Resolve some TODOs.

This commit is contained in:
John Blum
2021-09-27 12:43:28 -07:00
parent 9ed795cdef
commit 134cd92888
4 changed files with 35 additions and 57 deletions

View File

@@ -107,33 +107,39 @@ public abstract class AbstractAnnotationConfigSupport
private final Logger log;
/**
* Determines whether the given {@link Number} has value. The {@link Number} is valuable
* if it is not {@literal null} and is not equal to 0.0d.
* Determines whether the given {@link Number} has value.
*
* The {@link Number} is considered valuable if it is not {@literal null} and is not equal to {@literal 0.0d}.
*
* @param value {@link Number} to evaluate.
* @return a boolean value indicating whether the given {@link Number} has value.
* @see java.lang.Number
*/
public static boolean hasValue(@Nullable Number value) {
return Optional.ofNullable(value).filter(it -> it.doubleValue() != 0.0d).isPresent();
return value != null && value.doubleValue() != 0.0d;
}
/**
* Determines whether the given {@link Object} has value. The {@link Object} is valuable
* if it is not {@literal null}.
* Determines whether the given {@link Object} has value.
*
* The {@link Object} is considered valuable if it is not {@literal null}.
*
* @param value {@link Object} to evaluate.
* @return a boolean value indicating whether the given {@link Object} has value.
* @see java.lang.Object
*/
public static boolean hasValue(@Nullable Object value) {
return value != null;
}
/**
* Determines whether the given {@link String} has value. The {@link String} is valuable
* if it is not {@literal null} or empty.
* Determines whether the given {@link String} has value.
*
* The {@link String} is considered valuable if it is not {@literal null} and not {@literal empty}.
*
* @param value {@link String} to evaluate.
* @return a boolean value indicating whether the given {@link String} is valuable.
* @see java.lang.String
*/
public static boolean hasValue(@Nullable String value) {
return StringUtils.hasText(value);
@@ -154,6 +160,7 @@ public abstract class AbstractAnnotationConfigSupport
* @param beanFactory reference to the Spring {@link BeanFactory}.
* @see org.springframework.beans.factory.BeanFactory
* @see #newEvaluationContext(BeanFactory)
* @see #newLog()
*/
public AbstractAnnotationConfigSupport(@Nullable BeanFactory beanFactory) {

View File

@@ -94,7 +94,7 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
private List<GatewaySenderConfigurer> gatewaySenderConfigurers = Collections.emptyList();
// TODO: Come of with better association and remove.
// TODO: Come up with better association and remove.
private List<String> regions = new ArrayList<>();
private String diskStoreReference;

View File

@@ -26,19 +26,17 @@ 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.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate.FollowRedirectsSimpleClientHttpRequestFactory;
import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.ClusterSchemaObjectInitializer;
import static org.springframework.data.gemfire.config.annotation.ClusterConfigurationConfiguration.SchemaObjectContext;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.After;
import org.junit.Test;
@@ -57,9 +55,9 @@ import org.springframework.data.gemfire.config.admin.remote.FunctionGemfireAdmin
import org.springframework.data.gemfire.config.admin.remote.RestHttpGemfireAdminTemplate;
import org.springframework.data.gemfire.config.schema.support.ComposableSchemaObjectCollector;
import org.springframework.data.gemfire.config.schema.support.ComposableSchemaObjectDefiner;
import org.springframework.data.gemfire.tests.util.ReflectionUtils;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.InterceptingClientHttpRequestFactory;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.client.RestTemplate;
/**
@@ -83,42 +81,14 @@ import org.springframework.web.client.RestTemplate;
public class EnableClusterConfigurationUnitTests {
@After
public void tearDown() {
public void cleanupAfterEachTest() {
System.clearProperty(ClusterConfigurationConfiguration.HTTP_FOLLOW_REDIRECTS_PROPERTY);
}
// TODO: Replace with STDG!
private <T> ClusterConfigurationConfiguration autowire(ClusterConfigurationConfiguration target,
String fieldName, T dependency) throws NoSuchFieldException {
return Optional.ofNullable(ReflectionUtils.findField(target.getClass(), fieldName))
.map(field -> {
ReflectionUtils.makeAccessible(field);
return field;
})
.map(field -> {
ReflectionUtils.setField(field, target, dependency);
return target;
})
.orElseThrow(() ->
new NoSuchFieldException(String.format("Field [%s] was not found on Object of type [%s]",
fieldName, target.getClass().getName())));
}
@SuppressWarnings("unchecked")
private <T> T getFieldValue(Object target, String fieldName) throws NoSuchFieldException {
Field field = ReflectionUtils.findField(target.getClass(), fieldName);
return Optional.ofNullable(field)
.map(it -> {
ReflectionUtils.makeAccessible(it);
return field;
})
.map(it -> (T) ReflectionUtils.getField(it, target))
.orElseThrow(() ->
new NoSuchFieldException(String.format("Field with name [%s] was not found on Object of type [%s]",
fieldName, target.getClass().getName())));
return ReflectionUtils.setField(target, fieldName, dependency);
}
@Test
@@ -454,7 +424,7 @@ public class EnableClusterConfigurationUnitTests {
assertThat(configuration.resolveClientHttpRequestInterceptors(true))
.isEqualTo(clientHttpRequestInterceptors);
verifyZeroInteractions(mockBeanFactory);
verifyNoMoreInteractions(mockBeanFactory);
}
@Test
@@ -505,7 +475,7 @@ public class EnableClusterConfigurationUnitTests {
assertThat(clientHttpRequestInterceptors).isNotNull();
assertThat(clientHttpRequestInterceptors).isEmpty();
verifyZeroInteractions(mockBeanFactory);
verifyNoMoreInteractions(mockBeanFactory);
}
@Test
@@ -533,7 +503,7 @@ public class EnableClusterConfigurationUnitTests {
assertThat(operations).isInstanceOf(FunctionGemfireAdminTemplate.class);
verifyZeroInteractions(mockClientCache);
verifyNoMoreInteractions(mockClientCache);
}
@Test
@@ -562,7 +532,7 @@ public class EnableClusterConfigurationUnitTests {
RestHttpGemfireAdminTemplate template = (RestHttpGemfireAdminTemplate) operations;
RestTemplate restTemplate = getFieldValue(template, "restTemplate");
RestTemplate restTemplate = ReflectionUtils.getFieldValue(template, "restTemplate");
assertThat(restTemplate).isNotNull();
assertThat(restTemplate.getInterceptors()).isEmpty();
@@ -573,9 +543,10 @@ public class EnableClusterConfigurationUnitTests {
assertThat(clientHttpRequestFactory.isFollowRedirects()).isFalse();
verifyZeroInteractions(mockClientCache);
verify(configuration, times(1)).resolveClientHttpRequestInterceptors(eq(false));
verify(configuration, times(1)).resolveRestTemplateConfigurers();
verifyNoMoreInteractions(mockClientCache);
}
@Test
@@ -603,7 +574,7 @@ public class EnableClusterConfigurationUnitTests {
RestHttpGemfireAdminTemplate template = (RestHttpGemfireAdminTemplate) operations;
RestTemplate restTemplate = getFieldValue(template, "restTemplate");
RestTemplate restTemplate = ReflectionUtils.getFieldValue(template, "restTemplate");
assertThat(restTemplate).isNotNull();
assertThat(restTemplate.getInterceptors()).isEmpty();
@@ -614,9 +585,10 @@ public class EnableClusterConfigurationUnitTests {
assertThat(clientHttpRequestFactory.isFollowRedirects()).isTrue();
verifyZeroInteractions(mockClientCache);
verify(configuration, times(1)).resolveClientHttpRequestInterceptors(eq(false));
verify(configuration, times(1)).resolveRestTemplateConfigurers();
verifyNoMoreInteractions(mockClientCache);
}
@Test
@@ -652,20 +624,21 @@ public class EnableClusterConfigurationUnitTests {
RestHttpGemfireAdminTemplate template = (RestHttpGemfireAdminTemplate) operations;
RestTemplate restTemplate = getFieldValue(template, "restTemplate");
RestTemplate restTemplate = ReflectionUtils.getFieldValue(template, "restTemplate");
assertThat(restTemplate).isNotNull();
assertThat(restTemplate.getInterceptors()).containsExactly(mockInterceptorOne, mockInterceptorTwo);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(InterceptingClientHttpRequestFactory.class);
FollowRedirectsSimpleClientHttpRequestFactory clientHttpRequestFactory =
getFieldValue(restTemplate.getRequestFactory(), "requestFactory");
ReflectionUtils.getFieldValue(restTemplate.getRequestFactory(), "requestFactory");
assertThat(clientHttpRequestFactory.isFollowRedirects()).isTrue();
verifyZeroInteractions(mockClientCache);
verify(configuration, times(1)).resolveClientHttpRequestInterceptors(eq(true));
verify(configuration, times(1)).resolveRestTemplateConfigurers();
verifyNoMoreInteractions(mockClientCache);
}
@Test
@@ -696,11 +669,12 @@ public class EnableClusterConfigurationUnitTests {
RestHttpGemfireAdminTemplate template = (RestHttpGemfireAdminTemplate) operations;
assertThat(this.<String>getFieldValue(template, "managementRestApiUrl"))
assertThat(ReflectionUtils.<String>getFieldValue(template, "managementRestApiUrl"))
.isEqualTo("https://skullbox/gemfire/v1");
verifyZeroInteractions(mockClientCache);
verify(configuration, times(1)).resolveClientHttpRequestInterceptors(eq(false));
verify(configuration, times(1)).resolveRestTemplateConfigurers();
verifyNoMoreInteractions(mockClientCache);
}
}

View File

@@ -1048,9 +1048,6 @@ public class SpringContextBootstrappingInitializerUnitTests {
@Configuration
protected static class TestAppConfigTwo { }
// TODO add additional multi-threaded test cases once MultithreadedTC test framework is added to the SDP project
// in order to properly test concurrency of notification and registration during Spring ApplicationContext creation.
protected static class TestApplicationListener implements ApplicationListener<ContextRefreshedEvent> {
private volatile boolean notified = false;