Upgraded versions and fixed test
This commit upgrades the versions to the latest and greatest as well as removes the custom implementation of a TaskLauncher.
This commit is contained in:
@@ -16,16 +16,18 @@
|
||||
|
||||
package io.spring;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.spring.configuration.TaskSinkConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.deployer.spi.task.LaunchState;
|
||||
import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.launcher.TaskLaunchRequest;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -34,6 +36,8 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
@@ -49,11 +53,11 @@ public class TaskSinkApplicationTests {
|
||||
private Sink sink;
|
||||
|
||||
@Test
|
||||
public void testLaunch() {
|
||||
public void testLaunch() throws IOException {
|
||||
assertNotNull(this.sink.input());
|
||||
|
||||
TaskSinkConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskSinkConfiguration.TestTaskLauncher.class);
|
||||
TaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskLauncher.class);
|
||||
|
||||
Map<String, String> properties = new HashMap();
|
||||
properties.put("server.port", "0");
|
||||
@@ -63,6 +67,16 @@ public class TaskSinkApplicationTests {
|
||||
null, null);
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<TaskLaunchRequest>(request);
|
||||
this.sink.input().send(message);
|
||||
assertEquals(LaunchState.complete, testTaskLauncher.status("TESTSTATUS").getState());
|
||||
|
||||
ArgumentCaptor<AppDeploymentRequest> deploymentRequest = ArgumentCaptor.forClass(AppDeploymentRequest.class);
|
||||
|
||||
verify(testTaskLauncher).launch(deploymentRequest.capture());
|
||||
|
||||
AppDeploymentRequest actualRequest = deploymentRequest.getValue();
|
||||
|
||||
assertTrue(actualRequest.getCommandlineArguments().isEmpty());
|
||||
assertEquals("0", actualRequest.getDefinition().getProperties().get("server.port"));
|
||||
assertTrue(actualRequest.getResource().toString()
|
||||
.contains("maven://org.springframework.cloud.task.app:timestamp-task:jar:1.0.1.RELEASE"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
|
||||
package io.spring.configuration;
|
||||
|
||||
import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;
|
||||
import org.springframework.cloud.deployer.spi.task.LaunchState;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskStatus;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@@ -31,38 +30,7 @@ public class TaskSinkConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskLauncher taskLauncher() {
|
||||
return new TestTaskLauncher();
|
||||
}
|
||||
|
||||
public class TestTaskLauncher implements TaskLauncher {
|
||||
|
||||
public static final String LAUNCH_ID = "TEST_LAUNCH_ID";
|
||||
|
||||
private LaunchState state = LaunchState.unknown;
|
||||
|
||||
@Override
|
||||
public String launch(AppDeploymentRequest request) {
|
||||
state = LaunchState.complete;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(String id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskStatus status(String id) {
|
||||
String taskLaunchId = LAUNCH_ID;
|
||||
TaskStatus taskStatus = new TaskStatus(taskLaunchId, state, null);
|
||||
return taskStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup(String id) {}
|
||||
|
||||
@Override
|
||||
public void destroy(String appName) {}
|
||||
return mock(TaskLauncher.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user