001 package org.hackystat.sensorshell; 002 003 import static org.junit.Assert.assertEquals; 004 import static org.junit.Assert.assertFalse; 005 006 import java.io.File; 007 import java.util.Properties; 008 009 import org.junit.Test; 010 011 /** 012 * Provides simple unit tests for SensorShellProperties. 013 * @author Aaron A. Kagawa, Philip Johnson 014 */ 015 public class TestSensorShellProperties { 016 017 /** The test user. */ 018 private static String user = "TestShellUser@hackystat.org"; 019 private static String host = "http://TestHost/"; 020 021 /** 022 * Tests SensorProperties class when using the 'test' constructor. 023 * @throws Exception If problems occur. 024 */ 025 @Test public void testDefaultSensorProperties() throws Exception { 026 // Create a 'testing' version, that does not read sensorshell.properties and that disables 027 // caching and logging. 028 SensorShellProperties properties = SensorShellProperties.getTestInstance(host, user, user); 029 030 assertEquals("Check host", TestSensorShellProperties.host, properties.getSensorBaseHost()); 031 assertEquals("Check email", TestSensorShellProperties.user, properties.getSensorBaseUser()); 032 assertEquals("Check pass", TestSensorShellProperties.user, properties.getSensorBasePassword()); 033 assertEquals("Check auto send time interval", 1.0, properties.getAutoSendTimeInterval(), 0.01); 034 assertEquals("Check auto send buffer size", 250, properties.getAutoSendMaxBuffer()); 035 assertEquals("Check state change interval", 30, properties.getStateChangeInterval()); 036 assertFalse("Check multishell enabled", properties.isMultiShellEnabled()); 037 assertEquals("Check multishell numshells", 10, properties.getMultiShellNumShells()); 038 assertEquals("Check multishell batch size", 499, properties.getMultiShellBatchSize()); 039 assertEquals("Check multishell max buffer", 500, properties.getMultiShellMaxBuffer()); 040 assertFalse("Check offline caching", properties.isOfflineCacheEnabled()); 041 assertFalse("Check offline recovery", properties.isOfflineRecoveryEnabled()); 042 assertEquals("Check timeout", 10, properties.getTimeout()); 043 assertEquals("Check logging level", "OFF", properties.getLoggingLevel().getName()); 044 } 045 046 /** 047 * Tests SensorShellProperties class when using the Properties-based constructor. 048 * @throws Exception If problems occur. 049 */ 050 @Test public void testPropertiesConstructor() throws Exception { 051 Properties props = new Properties(); 052 props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_HOST_KEY, host); 053 props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_USER_KEY, user); 054 props.put(SensorShellProperties.SENSORSHELL_SENSORBASE_PASSWORD_KEY, user); 055 props.put(SensorShellProperties.SENSORSHELL_TIMEOUT_KEY, "5"); 056 // Use 'true' to force the timeout value specified above to override that property value 057 // if specified in the local sensorshell.properties file. 058 SensorShellProperties properties = new SensorShellProperties(props, true); 059 060 assertEquals("Check host", TestSensorShellProperties.host, properties.getSensorBaseHost()); 061 assertEquals("Check email", TestSensorShellProperties.user, properties.getSensorBaseUser()); 062 assertEquals("Check timeout", 5, properties.getTimeout()); 063 } 064 065 066 067 /** 068 * Tests basic functions of an invalid creation of a SensorProperties instance. 069 * @throws SensorShellException If problems occur. 070 */ 071 @Test(expected = SensorShellException.class) 072 public void testNullSensorProperties() throws SensorShellException { //NOPMD 073 new SensorShellProperties(null); 074 } 075 076 /** 077 * Tests basic functions of an invalid creation of a SensorProperties instance. 078 * @throws SensorShellException If problems occur. 079 */ 080 @Test(expected = SensorShellException.class) 081 public void testInvalidSensorProperties() throws SensorShellException { //NOPMD 082 new SensorShellProperties(new File("foobarbasbuz.properties")); 083 } 084 085 086 087 }