Change closecontextEnable to closeContextEnabled
Added test Updated to use the standard log library resolves #217
This commit is contained in:
committed by
Glenn Renfro
parent
bbb0d68ce6
commit
a1cffe8bd4
@@ -16,17 +16,23 @@
|
||||
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties available to configure the task.
|
||||
*
|
||||
* @author Glenn Renfro
|
||||
* @author David Turanski
|
||||
*/
|
||||
|
||||
@ConfigurationProperties(prefix = "spring.cloud.task")
|
||||
public class TaskProperties {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(TaskProperties.class);
|
||||
|
||||
public static final String DEFAULT_TABLE_PREFIX = "TASK_";
|
||||
|
||||
/**
|
||||
@@ -54,7 +60,7 @@ public class TaskProperties {
|
||||
* When set to true the context is closed at the end of the task. Else
|
||||
* the context remains open.
|
||||
*/
|
||||
private Boolean closecontextEnable = true;
|
||||
private Boolean closecontextEnabled = true;
|
||||
|
||||
public String getExternalExecutionId() {
|
||||
return externalExecutionId;
|
||||
@@ -72,12 +78,34 @@ public class TaskProperties {
|
||||
this.executionid = executionid;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated use getClosecontextEnabled()
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public Boolean getClosecontextEnable() {
|
||||
return closecontextEnable;
|
||||
return closecontextEnabled;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated use setClosecontextEnabled()
|
||||
* @since 1.2.0
|
||||
*/
|
||||
@Deprecated
|
||||
public void setClosecontextEnable(Boolean closecontextEnable) {
|
||||
this.closecontextEnable = closecontextEnable;
|
||||
logger.warn("'closecontextEnable' is deprecated. Use 'closeContextEnabled.'");
|
||||
this.closecontextEnabled = closecontextEnable;
|
||||
}
|
||||
|
||||
public Boolean getClosecontextEnabled() {
|
||||
return closecontextEnabled;
|
||||
}
|
||||
|
||||
public void setClosecontextEnabled(Boolean closecontextEnabled) {
|
||||
this.closecontextEnabled = closecontextEnabled;
|
||||
}
|
||||
|
||||
public String getTablePrefix() {
|
||||
|
||||
@@ -176,7 +176,7 @@ public class TaskLifecycleListener implements ApplicationListener<ApplicationEve
|
||||
|
||||
this.finished = true;
|
||||
|
||||
if(taskProperties.getClosecontextEnable() && this.context.isActive()) {
|
||||
if(taskProperties.getClosecontextEnabled() && this.context.isActive()) {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.springframework.cloud.task.configuration;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
|
||||
import org.springframework.cloud.task.repository.support.TaskExecutionDaoFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({
|
||||
TaskPropertiesTests.CloseContextEnableTest.class,
|
||||
TaskPropertiesTests.CloseContextEnabledTest.class,
|
||||
|
||||
})
|
||||
|
||||
@DirtiesContext
|
||||
public class TaskPropertiesTests {
|
||||
@Autowired
|
||||
TaskProperties taskProperties;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(taskProperties.getClosecontextEnabled(), is(false));
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes={TaskPropertiesTests.Config.class}, properties = { "spring.cloud.task.closecontextEnable=false" })
|
||||
@DirtiesContext
|
||||
public static class CloseContextEnableTest extends TaskPropertiesTests {
|
||||
}
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes={TaskPropertiesTests.Config.class}, properties = { "spring.cloud.task.closecontextEnabled=false" })
|
||||
@DirtiesContext
|
||||
public static class CloseContextEnabledTest extends TaskPropertiesTests {}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTask
|
||||
public static class Config {
|
||||
@Bean
|
||||
TaskExecutionDaoFactoryBean taskExecutionDaoFactoryBean() {
|
||||
return new TaskExecutionDaoFactoryBean();
|
||||
}
|
||||
@Bean
|
||||
public TaskRepository taskRepository(TaskExecutionDaoFactoryBean tefb) {
|
||||
return new SimpleTaskRepository(tefb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ will be used to build your project. Open your favorite text editor and add the
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.3.RELEASE</version>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -145,7 +145,7 @@ Spring Cloud Task itself:
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-task-core</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<version>1.2.0.BUILD-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
[[getting-started-writing-the-code]]
|
||||
@@ -305,7 +305,7 @@ to your tests will keep the context open. For example:
|
||||
```
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@TestPropertySource(properties = {"spring.cloud.task.closecontext_enable=false"})
|
||||
@TestPropertySource(properties = {"spring.cloud.task.closecontext_enabled=false"})
|
||||
public class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user