public static final String PORT_PROPERTY = "pPort";
public static final String MISSING_NAME_ARGUMENT = "Missing Name argument";
+ public static final String SONAR_HOME_IS_NOT_SET = "variable SONAR_HOME is not set.";
+ public static final String SONAR_HOME_DOES_NOT_EXIST = "Directory SONAR_HOME does not exist";
+ public static final String SONAR_HOME_IS_NOT_WRITABLE = "Directory SONAR_HOME is not writable";
private final static Logger LOGGER = LoggerFactory.getLogger(Process.class);
// check that we have a SONAR_HOME either in props or in env.
String sonarHome = props.of(SONAR_HOME, System.getenv(SONAR_HOME));
if (StringUtils.isEmpty(sonarHome)) {
- throw new IllegalStateException("variable SONAR_HOME is not set.");
+ throw new IllegalStateException(SONAR_HOME_IS_NOT_SET);
}
// check that SONAR_HOME exists
File home = new File(sonarHome);
if(!home.exists()) {
- throw new IllegalStateException("Directory SONAR_HOME '" + sonarHome + "' is not set");
+ throw new IllegalStateException(SONAR_HOME_DOES_NOT_EXIST);
}
// check that SONAR_HOME is writable
if (!home.canWrite()) {
- throw new IllegalStateException("Directory SONAR_HOME '" + sonarHome + "' is not writable");
+ throw new IllegalStateException(SONAR_HOME_IS_NOT_WRITABLE);
}
}
}
\ No newline at end of file
*/
package org.sonar.process;
+import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@Test
public void fail_missing_properties() {
Properties properties = new Properties();
+ try {
+ new TestProcess(Props.create(properties));
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo(Process.SONAR_HOME_IS_NOT_SET);
+ }
+
+ properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, "lahdslahdslf");
+ try {
+ new TestProcess(Props.create(properties));
+ } catch (Exception e) {
+ assertThat(e.getMessage()).isEqualTo(Process.SONAR_HOME_DOES_NOT_EXIST);
+ }
+
+ properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
try {
new TestProcess(Props.create(properties));
} catch (Exception e) {
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
Props props = Props.create(properties);
process = new TestProcess(props);
@Test(timeout = 5000L)
public void should_stop_explicit() throws Exception {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
Props props = Props.create(properties);
process = new TestProcess(props);
@Test(timeout = 15000L)
public void should_stop_implicit() throws Exception {
Properties properties = new Properties();
+ properties.setProperty(Process.SONAR_HOME, FileUtils.getTempDirectoryPath());
properties.setProperty(Process.NAME_PROPERTY, "TEST");
properties.setProperty(Process.PORT_PROPERTY, Integer.toString(freePort));
Props props = Props.create(properties);