mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testPropertiesNoConfigAdmin()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        when(context.getProperty(LogWriter.LOG_DAYS_ALIVE_PROPERTY)).thenReturn("1");
        when(context.getProperty(LogWriter.LOG_FILE_BUFFER_SIZE_PROPERTY)).thenReturn("2");
        when(context.getProperty(LogWriter.LOG_LEVEL_PROPERTY)).thenReturn(LogLevel.Warning.toString());
        when(context.getProperty(LogWriter.LOG_SIZE_PROPERTY)).thenReturn("2");
        // Setting key value pair
        m_SUT.activate(context, props);
        setUpFileNaming();

        long prelength = m_LogFile.length();

        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        // ask to log at a level too high
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        when(logEntry.getMessage()).thenReturn("AROOOGA!");
        m_SUT.logged(logEntry);

        //verify that data is not logged at the log level is no acceptable
        assertThat(m_LogFile.length(), is(prelength));

        //change level to acceptable range
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);

        //verify that the log entry was successful, this proves that even if the config admin is unavailable and there
        //are no properties known to the framework that the log service will still function.
        assertThat(m_LogFile.length(), greaterThan(prelength));
    }
/**
     * Test that if values are set in the property file that those values are used when config admin is not available.
     * Verify logging works with those values.
     */
Test that if values are set in the property file that those values are used when config admin is not available.
Verify logging works with those values.
Test that if values are set in the property file that those values are used when config admin is not available . Verify logging works with those values .
@Test
    public void testPropertiesNoConfigAdmin()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        when(context.getProperty(LogWriter.LOG_DAYS_ALIVE_PROPERTY)).thenReturn("1");
        when(context.getProperty(LogWriter.LOG_FILE_BUFFER_SIZE_PROPERTY)).thenReturn("2");
        when(context.getProperty(LogWriter.LOG_LEVEL_PROPERTY)).thenReturn(LogLevel.Warning.toString());
        when(context.getProperty(LogWriter.LOG_SIZE_PROPERTY)).thenReturn("2");
        m_SUT.activate(context, props);
        setUpFileNaming();
        long prelength = m_LogFile.length();
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        when(logEntry.getMessage()).thenReturn("AROOOGA!");
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), is(prelength));
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), greaterThan(prelength));
    }
@ Test public void testPropertiesNoConfigAdmin ( ) { BundleContext context = mock ( BundleContext . class ) ; Map < String , Object > props = new HashMap < String , Object > ( getComponentProperties ( ) ) ; when ( context . getProperty ( LogWriter . LOG_DIR_PROPERTY ) ) . thenReturn ( "TempLogDir" ) ; when ( context . getProperty ( LogWriter . LOG_DAYS_ALIVE_PROPERTY ) ) . thenReturn ( "1" ) ; when ( context . getProperty ( LogWriter . LOG_FILE_BUFFER_SIZE_PROPERTY ) ) . thenReturn ( "2" ) ; when ( context . getProperty ( LogWriter . LOG_LEVEL_PROPERTY ) ) . thenReturn ( LogLevel . Warning . toString ( ) ) ; when ( context . getProperty ( LogWriter . LOG_SIZE_PROPERTY ) ) . thenReturn ( "2" ) ; m_SUT . activate ( context , props ) ; setUpFileNaming ( ) ; long prelength = m_LogFile . length ( ) ; LogEntry logEntry = mock ( LogEntry . class ) ; when ( logEntry . getBundle ( ) ) . thenReturn ( m_Bundle ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_DEBUG ) ; when ( logEntry . getTime ( ) ) . thenReturn ( 1L ) ; when ( logEntry . getMessage ( ) ) . thenReturn ( "AROOOGA!" ) ; m_SUT . logged ( logEntry ) ; assertThat ( m_LogFile . length ( ) , is ( prelength ) ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_ERROR ) ; m_SUT . logged ( logEntry ) ; assertThat ( m_LogFile . length ( ) , greaterThan ( prelength ) ) ; }
Test that if values are set in the property file that those values are used when config admin is not available.
Test that if values are set in the property file that those values are used when config admin is not available .
// Setting key value pair // ask to log at a level too high //verify that data is not logged at the log level is no acceptable //change level to acceptable range //verify that the log entry was successful, this proves that even if the config admin is unavailable and there //are no properties known to the framework that the log service will still function.