Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected JobLauncher createJobLauncher() throws Exception {
protected JobRepository createJobRepository() throws Exception {
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
PropertyMapper map = PropertyMapper.get();
map.from(() -> this.dataSource).to(factory::setDataSource);
map.from(this.dataSource).to(factory::setDataSource);
map.from(this::determineIsolationLevel).whenNonNull()
.to(factory::setIsolationLevelForCreate);
map.from(this.properties::getTablePrefix).whenHasText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ private void configureListenerFactory(
PropertyMapper map = PropertyMapper.get();
Listener properties = this.properties.getListener();
map.from(properties::getConcurrency).whenNonNull().to(factory::setConcurrency);
map.from(() -> this.messageConverter).whenNonNull()
.to(factory::setMessageConverter);
map.from(() -> this.replyTemplate).whenNonNull().to(factory::setReplyTemplate);
map.from(this.messageConverter).whenNonNull().to(factory::setMessageConverter);
map.from(this.replyTemplate).whenNonNull().to(factory::setReplyTemplate);
map.from(properties::getType).whenEqualTo(Listener.Type.BATCH)
.toCall(() -> factory.setBatchListener(true));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
tomcatProperties.getMaxThreads()));
propertyMapper.from(tomcatProperties::getMinSpareThreads).when(this::isPositive)
.to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
propertyMapper.from(() -> determineMaxHttpHeaderSize()).when(this::isPositive)
propertyMapper.from(this::determineMaxHttpHeaderSize).when(this::isPositive)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void customize(ConfigurableUndertowWebServerFactory factory) {
.to(factory::setAccessLogSuffix);
propertyMapper.from(accesslogProperties::isRotate)
.to(factory::setAccessLogRotate);
propertyMapper.from(() -> getOrDeduceUseForwardHeaders())
propertyMapper.from(this::getOrDeduceUseForwardHeaders)
.to(factory::setUseForwardHeaders);
propertyMapper.from(properties::getMaxHttpHeaderSize).when(this::isPositive)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ public void setResolveLazily(boolean resolveLazily) {
public MultipartConfigElement createMultipartConfig() {
MultipartConfigFactory factory = new MultipartConfigFactory();
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(() -> this.fileSizeThreshold).to(factory::setFileSizeThreshold);
map.from(() -> this.location).whenHasText().to(factory::setLocation);
map.from(() -> this.maxRequestSize).to(factory::setMaxRequestSize);
map.from(() -> this.maxFileSize).to(factory::setMaxFileSize);
map.from(this.fileSizeThreshold).to(factory::setFileSizeThreshold);
map.from(this.location).whenHasText().to(factory::setLocation);
map.from(this.maxRequestSize).to(factory::setMaxRequestSize);
map.from(this.maxFileSize).to(factory::setMaxFileSize);
return factory.createMultipartConfig();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ public PropertyMapper alwaysApplying(SourceOperator operator) {
return new PropertyMapper(this, operator);
}

/**
* Return a new {@link Source} from the specified value that can be used to perform
* the mapping.
* @param <T> the source type
* @param value the value
* @return a {@link Source} that can be used to complete the mapping
* @see #from(Supplier)
*/
public <T> Source<T> from(T value) {
return from(() -> value);
}

/**
* Return a new {@link Source} from the specified value supplier that can be used to
* perform the mapping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,15 @@ public <T extends ThreadPoolTaskExecutor> T build(Class<T> taskExecutorClass) {
*/
public <T extends ThreadPoolTaskExecutor> T configure(T taskExecutor) {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(() -> this.queueCapacity).to(taskExecutor::setQueueCapacity);
map.from(() -> this.corePoolSize).to(taskExecutor::setCorePoolSize);
map.from(() -> this.maxPoolSize).to(taskExecutor::setMaxPoolSize);
map.from(() -> this.keepAlive).asInt(Duration::getSeconds)
map.from(this.queueCapacity).to(taskExecutor::setQueueCapacity);
map.from(this.corePoolSize).to(taskExecutor::setCorePoolSize);
map.from(this.maxPoolSize).to(taskExecutor::setMaxPoolSize);
map.from(this.keepAlive).asInt(Duration::getSeconds)
.to(taskExecutor::setKeepAliveSeconds);
map.from(() -> this.allowCoreThreadTimeOut)
.to(taskExecutor::setAllowCoreThreadTimeOut);
map.from(() -> this.threadNamePrefix).whenHasText()
map.from(this.allowCoreThreadTimeOut).to(taskExecutor::setAllowCoreThreadTimeOut);
map.from(this.threadNamePrefix).whenHasText()
.to(taskExecutor::setThreadNamePrefix);
map.from(() -> this.taskDecorator).to(taskExecutor::setTaskDecorator);
map.from(this.taskDecorator).to(taskExecutor::setTaskDecorator);

if (!CollectionUtils.isEmpty(this.taskExecutorCustomizers)) {
for (TaskExecutorCustomizer customizer : this.taskExecutorCustomizers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public ThreadPoolTaskScheduler build() {
*/
public <T extends ThreadPoolTaskScheduler> T configure(T taskScheduler) {
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
map.from(() -> this.poolSize).to(taskScheduler::setPoolSize);
map.from(() -> this.threadNamePrefix).to(taskScheduler::setThreadNamePrefix);
map.from(this.poolSize).to(taskScheduler::setPoolSize);
map.from(this.threadNamePrefix).to(taskScheduler::setThreadNamePrefix);

if (!CollectionUtils.isEmpty(this.taskSchedulerCustomizers)) {
for (TaskSchedulerCustomizer customizer : this.taskSchedulerCustomizers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,12 @@ public <T extends WebServiceTemplate> T configure(T webServiceTemplate) {
configureMessageSenders(webServiceTemplate);
PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();
applyCustomizers(webServiceTemplate, this.internalCustomizers);
map.from(() -> this.marshaller).to(webServiceTemplate::setMarshaller);
map.from(() -> this.unmarshaller).to(webServiceTemplate::setUnmarshaller);
map.from(() -> this.destinationProvider)
.to(webServiceTemplate::setDestinationProvider);
map.from(() -> this.transformerFactoryClass)
map.from(this.marshaller).to(webServiceTemplate::setMarshaller);
map.from(this.unmarshaller).to(webServiceTemplate::setUnmarshaller);
map.from(this.destinationProvider).to(webServiceTemplate::setDestinationProvider);
map.from(this.transformerFactoryClass)
.to(webServiceTemplate::setTransformerFactoryClass);
map.from(() -> this.messageFactory).to(webServiceTemplate::setMessageFactory);
map.from(this.messageFactory).to(webServiceTemplate::setMessageFactory);
if (!CollectionUtils.isEmpty(this.interceptors)) {
Set<ClientInterceptor> merged = new LinkedHashSet<>(this.interceptors);
if (webServiceTemplate.getInterceptors() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,37 @@ public class PropertyMapperTests {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void fromNullValue() {
ExampleDest dest = new ExampleDest();
this.map.from((String) null).to(dest::setName);
assertThat(dest.getName()).isNull();
}

@Test
public void fromValue() {
ExampleDest dest = new ExampleDest();
this.map.from("Hello World").to(dest::setName);
assertThat(dest.getName()).isEqualTo("Hello World");
}

@Test
public void fromValueAsIntShouldAdaptSupplier() {
Integer result = this.map.from("123").asInt(Long::valueOf)
.toInstance(Integer::new);
assertThat(result).isEqualTo(123);
}

@Test
public void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assert::fail);
}

@Test
public void fromWhenSupplierIsNullShouldThrowException() {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Supplier must not be null");
this.map.from(null);
this.map.from((Supplier<?>) null);
}

@Test
Expand Down