Java Code Examples for org.springframework.cloud.task.repository.TaskExecution#setArguments()

The following examples show how to use org.springframework.cloud.task.repository.TaskExecution#setArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleCommandLineArgsProviderTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppending() {
	List<String> appendedValues = new ArrayList<>(3);
	appendedValues.add("one");
	appendedValues.add("two");
	appendedValues.add("three");

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));

	SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
			taskExecution);
	provider.setAppendedArgs(appendedValues);

	List<String> commandLineArgs = provider.getCommandLineArgs(null);

	assertThat(commandLineArgs.get(0)).isEqualTo("foo");
	assertThat(commandLineArgs.get(1)).isEqualTo("bar");
	assertThat(commandLineArgs.get(2)).isEqualTo("baz");
	assertThat(commandLineArgs.get(3)).isEqualTo("one");
	assertThat(commandLineArgs.get(4)).isEqualTo("two");
	assertThat(commandLineArgs.get(5)).isEqualTo("three");
}
 
Example 2
Source File: SimpleCommandLineArgsProviderTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppendingNull() {

	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));

	SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
			taskExecution);
	provider.setAppendedArgs(null);

	List<String> commandLineArgs = provider.getCommandLineArgs(null);

	assertThat(commandLineArgs.size()).isEqualTo(3);
	assertThat(commandLineArgs.get(0)).isEqualTo("foo");
	assertThat(commandLineArgs.get(1)).isEqualTo("bar");
	assertThat(commandLineArgs.get(2)).isEqualTo("baz");
}
 
Example 3
Source File: JdbcTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Override
public TaskExecution getTaskExecution(long executionId) {
	final MapSqlParameterSource queryParameters = new MapSqlParameterSource()
			.addValue("taskExecutionId", executionId, Types.BIGINT);

	try {
		TaskExecution taskExecution = this.jdbcTemplate.queryForObject(
				getQuery(GET_EXECUTION_BY_ID), queryParameters,
				new TaskExecutionRowMapper());
		taskExecution.setArguments(getTaskArguments(executionId));
		return taskExecution;
	}
	catch (EmptyResultDataAccessException e) {
		return null;
	}
}
 
Example 4
Source File: MapTaskExecutionDaoTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartTaskExecution() {
	TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
			new ArrayList<>(0), null);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());
	Map<Long, TaskExecution> taskExecutionMap = this.mapTaskExecutionDao
			.getTaskExecutions();
	assertThat(taskExecutionMap).as("taskExecutionMap must not be null").isNotNull();
	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
			taskExecutionMap.get(expectedTaskExecution.getExecutionId()));
}
 
Example 5
Source File: JdbcTaskExecutionDaoTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void testStartTaskExecution() {
	TaskExecution expectedTaskExecution = this.dao.createTaskExecution(null, null,
			new ArrayList<>(0), null);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	this.dao.startTaskExecution(expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution,
			TestDBUtils.getTaskExecutionFromDB(this.dataSource,
					expectedTaskExecution.getExecutionId()));
}
 
Example 6
Source File: SimpleTaskRepositoryMapTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void startTaskExecutionWithParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId(),
			expectedTaskExecution.getParentExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 7
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext
public void startTaskExecutionWithParam() {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreEmptyTaskExecution(this.taskRepository);

	expectedTaskExecution.setArguments(
			Collections.singletonList("foo=" + UUID.randomUUID().toString()));
	expectedTaskExecution.setStartTime(new Date());
	expectedTaskExecution.setTaskName(UUID.randomUUID().toString());

	TaskExecution actualTaskExecution = this.taskRepository.startTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getTaskName(), expectedTaskExecution.getStartTime(),
			expectedTaskExecution.getArguments(),
			expectedTaskExecution.getExternalExecutionId());

	TestVerifierUtils.verifyTaskExecution(expectedTaskExecution, actualTaskExecution);
}
 
Example 8
Source File: TaskSanitizerTest.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Test
public void testTaskExecutionArguments() {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setTaskName("a1");
	taskExecution.setArguments(Arrays.asList("--username=test", "--password=testing"));
	TaskExecution sanitizedTaskExecution = this.taskSanitizer.sanitizeTaskExecutionArguments(taskExecution);
	Assert.assertEquals("--username=******", sanitizedTaskExecution.getArguments().get(0));
	Assert.assertEquals("--password=******", sanitizedTaskExecution.getArguments().get(1));
}
 
Example 9
Source File: SimpleCommandLineArgsProviderTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
	TaskExecution taskExecution = new TaskExecution();
	taskExecution.setArguments(Arrays.asList("foo", "bar", "baz"));

	SimpleCommandLineArgsProvider provider = new SimpleCommandLineArgsProvider(
			taskExecution);

	List<String> commandLineArgs = provider.getCommandLineArgs(null);

	assertThat(commandLineArgs.get(0)).isEqualTo("foo");
	assertThat(commandLineArgs.get(1)).isEqualTo("bar");
	assertThat(commandLineArgs.get(2)).isEqualTo("baz");
}
 
Example 10
Source File: MapTaskExecutionDao.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public TaskExecution startTaskExecution(long executionId, String taskName,
		Date startTime, List<String> arguments, String externalExecutionid,
		Long parentExecutionId) {
	TaskExecution taskExecution = this.taskExecutions.get(executionId);
	taskExecution.setTaskName(taskName);
	taskExecution.setStartTime(startTime);
	taskExecution.setArguments(arguments);
	taskExecution.setParentExecutionId(parentExecutionId);
	if (externalExecutionid != null) {
		taskExecution.setExternalExecutionId(externalExecutionid);
	}
	return taskExecution;
}
 
Example 11
Source File: TaskExecutionCreator.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a sample TaskExecution and stores it in the taskRepository with params.
 * @param taskRepository the taskRepository where the taskExecution should be stored.
 * @return the taskExecution created.
 */
public static TaskExecution createAndStoreTaskExecutionWithParams(
		TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = TestVerifierUtils
			.createSampleTaskExecutionNoArg();
	List<String> params = new ArrayList<>();
	params.add(UUID.randomUUID().toString());
	params.add(UUID.randomUUID().toString());
	expectedTaskExecution.setArguments(params);
	expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution);
	return expectedTaskExecution;
}
 
Example 12
Source File: TestDBUtils.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private static void populateParamsToDB(DataSource dataSource,
		TaskExecution taskExecution) {
	String sql = "SELECT * FROM TASK_EXECUTION_PARAMS WHERE TASK_EXECUTION_ID = '"
			+ taskExecution.getExecutionId() + "'";

	JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
	List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql);
	List<String> arguments = new ArrayList<>();
	for (Map row : rows) {
		arguments.add((String) row.get("TASK_PARAM"));
	}
	taskExecution.setArguments(arguments);
}
 
Example 13
Source File: TaskSanitizer.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public TaskExecution sanitizeTaskExecutionArguments(TaskExecution taskExecution) {
	List<String> args = taskExecution.getArguments().stream()
			.map(argument -> (this.argumentSanitizer.sanitize(argument))).collect(Collectors.toList());
	taskExecution.setArguments(args);
	return taskExecution;
}