mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testLogLevelProperty() throws Exception
    {
        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_LEVEL_PROPERTY)).thenReturn(LogLevel.Warning.toString());

        // Setting key value pair
        m_SUT.activate(context, props);
        // This is to mimic the log file created during activation.
        setUpFileNaming();

        // testing that activation/openLogFile methods
        long fileLength = m_LogFile.length();

        // log entry
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        m_SUT.logged(logEntry);
        //should no be larger because debug is log level 4
        assertThat(m_LogFile.length(), is(fileLength));

        //replay this time including the debug log level
        when(context.getProperty(LogWriter.LOG_LEVEL_PROPERTY)).thenReturn(LogLevel.Debug.toString());
        m_SUT.modified(props);

        // testing that activation/openLogFile methods
        fileLength = m_LogFile.length();

        // log entry
        m_SUT.logged(logEntry);
        //should be immediately be larger
        assertThat(m_LogFile.length(), greaterThan(fileLength));
    }
/**
     * Test reading the log level property from the property file.
     */
Test reading the log level property from the property file.
Test reading the log level property from the property file .
@Test
    public void testLogLevelProperty() throws Exception
    {
        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_LEVEL_PROPERTY)).thenReturn(LogLevel.Warning.toString());
        m_SUT.activate(context, props);
        setUpFileNaming();
        long fileLength = 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);
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), is(fileLength));
        when(context.getProperty(LogWriter.LOG_LEVEL_PROPERTY)).thenReturn(LogLevel.Debug.toString());
        m_SUT.modified(props);
        fileLength = m_LogFile.length();
        m_SUT.logged(logEntry);
        assertThat(m_LogFile.length(), greaterThan(fileLength));
    }
@ Test public void testLogLevelProperty ( ) throws Exception { 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_LEVEL_PROPERTY ) ) . thenReturn ( LogLevel . Warning . toString ( ) ) ; m_SUT . activate ( context , props ) ; setUpFileNaming ( ) ; long fileLength = 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 ) ; m_SUT . logged ( logEntry ) ; assertThat ( m_LogFile . length ( ) , is ( fileLength ) ) ; when ( context . getProperty ( LogWriter . LOG_LEVEL_PROPERTY ) ) . thenReturn ( LogLevel . Debug . toString ( ) ) ; m_SUT . modified ( props ) ; fileLength = m_LogFile . length ( ) ; m_SUT . logged ( logEntry ) ; assertThat ( m_LogFile . length ( ) , greaterThan ( fileLength ) ) ; }
Test reading the log level property from the property file.
Test reading the log level property from the property file .
// Setting key value pair // This is to mimic the log file created during activation. // testing that activation/openLogFile methods // log entry //should no be larger because debug is log level 4 //replay this time including the debug log level // testing that activation/openLogFile methods // log entry //should be immediately be larger