/*
* JBoss, Home of Professional Open Source.
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.bootstrap.test.jboot11.unit;
import java.io.File;
import java.util.Properties;
import junit.framework.TestCase;
import org.jboss.bootstrap.microcontainer.ServerImpl;
import org.jboss.bootstrap.spi.Server;
import org.jboss.bootstrap.spi.ServerConfig;
import org.jboss.bootstrap.test.common.ServerConfigUtil;
import org.jboss.logging.Logger;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* FileFromServerConfigPropertyTestCase
*
* Tests to ensure that File objects may be constructed from
* the properties made by the ServerConfig
*
* @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
* @version $Revision: $
*/
public class FileFromServerConfigPropertyTestCase
{
//-----------------------------------------------------------------------------||
// Class Members --------------------------------------------------------------||
//-----------------------------------------------------------------------------||
private static final Logger log = Logger.getLogger(FileFromServerConfigPropertyTestCase.class);
//-----------------------------------------------------------------------------||
// Lifecycle Methods ----------------------------------------------------------||
//-----------------------------------------------------------------------------||
/**
* Runs once before the suite, initializes the Server such that
* the requisite System Properties are put in place
*/
@BeforeClass
public static void initServerToMakeProperties() throws Throwable
{
// Create properties (and JBOSS_HOME)
final Properties props = new Properties();
props.put(ServerConfig.HOME_DIR, ServerConfigUtil.getJBossHomeFromCurrentLocation("jbossas").toString());
// Create and perform minimal initialization upon a new server
final Server server = new ServerImpl();
server.init(props);
}
//-----------------------------------------------------------------------------||
// Tests ----------------------------------------------------------------------||
//-----------------------------------------------------------------------------||
/**
* Ensures that a valid File may be made from
* jboss.server.base.dir
*
* @throws Exception
*/
@Test
public void testFileFromJbossHomeDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.HOME_DIR);
}
/**
* Ensures that a valid File may be made from
* jboss.home
*
* @throws Exception
*/
@Test
public void testFileFromServerBaseDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.SERVER_BASE_DIR);
}
/**
* Ensures that a valid File may be made from
* jboss.server.home.dir
*
* @throws Exception
*/
@Test
public void testFileFromServerHomeDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.SERVER_HOME_DIR);
}
/**
* Ensures that a valid File may be made from
* jboss.server.log.dir
*
* @throws Exception
*/
@Test
public void testFileFromServerLogDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.SERVER_LOG_DIR);
}
/**
* Ensures that a valid File may be made from
* jboss.server.temp.dir
*
* @throws Exception
*/
@Test
public void testFileFromServerTempDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.SERVER_TEMP_DIR);
}
/**
* Ensures that a valid File may be made from
* jboss.server.data.dir
*
* @throws Exception
*/
@Test
public void testFileFromServerDataDirProperty() throws Exception
{
this.ensureFileFromPropertyExists(ServerConfig.SERVER_DATA_DIR);
}
//-----------------------------------------------------------------------------||
// Internal Helper Methods ----------------------------------------------------||
//-----------------------------------------------------------------------------||
/**
* Ensures that a File may be constructed from the value of specified
* System Property name, and that it exists
*/
private void ensureFileFromPropertyExists(final String propertyName) throws Exception
{
// Get the system property
final String propertyValue = System.getProperty(propertyName);
log.info(propertyName + " is: " + propertyValue);
// Make a File, ensure it exists
File fileFromPropertyValue = new File(propertyValue);
TestCase.assertTrue(propertyName + " could not be made into a " + File.class.getName() + ": "
+ fileFromPropertyValue.getAbsolutePath(), fileFromPropertyValue.exists());
}
}