Added TaskNameResolver and related implementation
TaskNameResolver allows the ability to customize how a task is named. During normal use cases, the provided SimpleTaskNameResolver should suffice. resolves spring-cloud/spring-cloud-task#54
This commit is contained in:
committed by
Glenn Renfro
parent
a2674b50bd
commit
1c3bb94bbd
@@ -35,8 +35,6 @@ import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -44,6 +42,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
||||
@@ -54,7 +53,6 @@ import org.springframework.cloud.task.repository.TaskExplorer;
|
||||
import org.springframework.cloud.task.repository.dao.TaskExecutionDao;
|
||||
import org.springframework.cloud.task.util.TestVerifierUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -67,18 +65,12 @@ public class SimpleTaskExplorerTests {
|
||||
|
||||
private AnnotationConfigApplicationContext context;
|
||||
|
||||
@Autowired(required = false)
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private TaskExecutionDao dao;
|
||||
|
||||
@Autowired
|
||||
private TaskExplorer taskExplorer;
|
||||
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
private DaoType testType;
|
||||
|
||||
@Parameterized.Parameters
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2016 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
|
||||
*
|
||||
* http://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.cloud.task.repository.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class SimpleTaskNameResolverTests {
|
||||
|
||||
@Test
|
||||
public void testDefault() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertTrue(taskNameResolver.getTaskName().startsWith("org.springframework.context.support.GenericApplicationContext"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testApplicationName() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.setId("foo");
|
||||
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
assertEquals("foo", taskNameResolver.getTaskName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExternalConfig() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.setId("foo");
|
||||
|
||||
SimpleTaskNameResolver taskNameResolver = new SimpleTaskNameResolver();
|
||||
taskNameResolver.setApplicationContext(context);
|
||||
|
||||
taskNameResolver.setConfiguredName("bar");
|
||||
|
||||
assertEquals("bar", taskNameResolver.getTaskName());
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
package org.springframework.cloud.task.util;
|
||||
|
||||
import org.springframework.cloud.task.listener.TaskLifecycleListener;
|
||||
import org.springframework.cloud.task.listener.TaskLifecycleListener;
|
||||
import org.springframework.cloud.task.repository.TaskNameResolver;
|
||||
import org.springframework.cloud.task.repository.TaskRepository;
|
||||
import org.springframework.cloud.task.repository.dao.MapTaskExecutionDao;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskNameResolver;
|
||||
import org.springframework.cloud.task.repository.support.SimpleTaskRepository;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -36,8 +38,13 @@ public class TestDefaultConfiguration {
|
||||
return new SimpleTaskRepository(new MapTaskExecutionDao());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskNameResolver taskNameResolver() {
|
||||
return new SimpleTaskNameResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TaskLifecycleListener taskHandler(){
|
||||
return new TaskLifecycleListener(taskRepository());
|
||||
return new TaskLifecycleListener(taskRepository(), taskNameResolver());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user