Add parent directory creation
Also tidied a few other things up (like not needing SmartApplicationListener). Fixes gh-550
This commit is contained in:
@@ -16,35 +16,56 @@
|
||||
|
||||
package org.springframework.boot.actuate.system;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Created by jkubrynski@gmail.com / 2014-03-25
|
||||
* @author Jakub Kubrynski
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class ApplicationPidListenerTest {
|
||||
|
||||
private static final String[] NO_ARGS = {};
|
||||
|
||||
public static final String PID_FILE_NAME = "test.pid";
|
||||
@After
|
||||
public void init() {
|
||||
ApplicationPidListener.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreatePidFile() {
|
||||
//given
|
||||
ApplicationPidListener sut = new ApplicationPidListener();
|
||||
sut.setPidFileName(PID_FILE_NAME);
|
||||
// given
|
||||
String pidFileName = "test.pid";
|
||||
ApplicationPidListener sut = new ApplicationPidListener(pidFileName);
|
||||
|
||||
//when
|
||||
sut.onApplicationEvent(new ApplicationStartedEvent(
|
||||
new SpringApplication(), NO_ARGS));
|
||||
// when
|
||||
sut.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(),
|
||||
NO_ARGS));
|
||||
|
||||
//then
|
||||
File pidFile = new File(PID_FILE_NAME);
|
||||
// then
|
||||
File pidFile = new File(pidFileName);
|
||||
assertTrue(pidFile.exists());
|
||||
pidFile.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreatePidFileParentDirectory() {
|
||||
// given
|
||||
String pidFileName = "target/pid/test.pid";
|
||||
ApplicationPidListener sut = new ApplicationPidListener(pidFileName);
|
||||
|
||||
// when
|
||||
sut.onApplicationEvent(new ApplicationStartedEvent(new SpringApplication(),
|
||||
NO_ARGS));
|
||||
|
||||
// then
|
||||
File pidFile = new File(pidFileName);
|
||||
assertTrue(pidFile.exists());
|
||||
pidFile.delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user