Server { public void init() throws ServerException { if (status != Status.UNDEF) { throw new IllegalStateException("Server already initialized"); } status = Status.BOOTING; verifyDir(homeDir); verifyDir(tempDir); Properties serverInfo = new Properties(); try { InputStream is = getResource(name + ".properties"); serverInfo.load(is); is.close(); } catch (IOException ex) { throw new RuntimeException( "Could not load server information file: " + name + ".properties"); } initLog(); log.info("++++++++++++++++++++++++++++++++++++++++++++++++++++++"); log.info("Server [{}] starting", name); log.info(" Built information:"); log.info(" Version : {}", serverInfo.getProperty(name + ".version", "undef")); log.info(" Source Repository : {}", serverInfo.getProperty(name + ".source.repository", "undef")); log.info(" Source Revision : {}", serverInfo.getProperty(name + ".source.revision", "undef")); log.info(" Built by : {}", serverInfo.getProperty(name + ".build.username", "undef")); log.info(" Built timestamp : {}", serverInfo.getProperty(name + ".build.timestamp", "undef")); log.info(" Runtime information:"); log.info(" Home dir: {}", homeDir); log.info(" Config dir: {}", (config == null) ? configDir : "-"); log.info(" Log dir: {}", logDir); log.info(" Temp dir: {}", tempDir); initConfig(); log.debug("Loading services"); List<Service> list = loadServices(); try { log.debug("Initializing services"); initServices(list); log.info("Services initialized"); } catch (ServerException ex) { log.error( "Services initialization failure, destroying initialized services"); destroyServices(); throw ex; } Status status = Status.valueOf(getConfig() .get(getPrefixedName(CONF_STARTUP_STATUS), Status.NORMAL.toString())); setStatus(status); log.info("Server [{}] started!, status [{}]", name, status); } Server(String name, String homeDir);  Server(String name, String homeDir, String configDir, String logDir,
      String tempDir);  Server(String name, String homeDir, Configuration config);  Server(String name, String homeDir, String configDir, String logDir,
      String tempDir, Configuration config); Status getStatus(); void setStatus(Status status); void init(); void destroy(); String getName(); String getPrefix(); String getPrefixedName(String name); String getHomeDir(); String getConfigDir(); String getLogDir(); String getTempDir(); Configuration getConfig(); @SuppressWarnings("unchecked") T get(Class<T> serviceKlass); void setService(Class<? extends Service> klass); static final String CONF_SERVICES; static final String CONF_SERVICES_EXT; static final String CONF_STARTUP_STATUS; static final String DEFAULT_LOG4J_PROPERTIES; }
@Test @TestException(exception = ServerException.class, msgRegExp = "S05.*") @TestDir public void siteFileNotAFile() throws Exception { String homeDir = TestDirHelper.getTestDir().getAbsolutePath(); File siteFile = new File(homeDir, "server-site.xml"); assertTrue(siteFile.mkdir()); Server server = new Server("server", homeDir, homeDir, homeDir, homeDir); server.init(); }
@Test(expected = IllegalStateException.class) @TestDir public void illegalState4() throws Exception { String dir = TestDirHelper.getTestDir().getAbsolutePath(); Server server = new Server("server", dir, dir, dir, dir, new Configuration(false)); server.init(); server.init(); }
@Test @TestException(exception = ServerException.class, msgRegExp = "S08.*") @TestDir public void invalidSservice() throws Exception { String dir = TestDirHelper.getTestDir().getAbsolutePath(); Configuration conf = new Configuration(false); conf.set("server.services", "foo"); Server server = new Server("server", dir, dir, dir, dir, conf); server.init(); }