mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testLogLevel()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        props.put("logLevel", LogLevel.Error.toString());
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");

        // 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);

        // clear buffer and make sure that the file is the same size as it was in the beginning
        m_SUT.deactivate();
        assertThat(m_LogFile.length(), is(prelength));
        m_LogFile.delete();

        // start the log writer again
        m_SUT.activate(context, props);
        // This is to mimic the log file created during activation.
        setUpFileNaming();
        prelength = m_LogFile.length();

        // log for the correct level
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);

        // clear buffer and make sure the log file is bigger.
        m_SUT.deactivate();
        assertThat(m_LogFile.length(), greaterThan(prelength));
    }
/**
     * Test setting the log level.
     * Verify that only message meeting the levels severity or greater are logged.
     */
Test setting the log level.
Verify that only message meeting the levels severity or greater are logged.
Test setting the log level . Verify that only message meeting the levels severity or greater are logged .
@Test
    public void testLogLevel()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        props.put("logLevel", LogLevel.Error.toString());
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        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);
        m_SUT.deactivate();
        assertThat(m_LogFile.length(), is(prelength));
        m_LogFile.delete();
        m_SUT.activate(context, props);
        setUpFileNaming();
        prelength = m_LogFile.length();
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);
        m_SUT.deactivate();
        assertThat(m_LogFile.length(), greaterThan(prelength));
    }
@ Test public void testLogLevel ( ) { BundleContext context = mock ( BundleContext . class ) ; Map < String , Object > props = new HashMap < String , Object > ( getComponentProperties ( ) ) ; props . put ( "logLevel" , LogLevel . Error . toString ( ) ) ; when ( context . getProperty ( LogWriter . LOG_DIR_PROPERTY ) ) . thenReturn ( "TempLogDir" ) ; 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 ) ; m_SUT . deactivate ( ) ; assertThat ( m_LogFile . length ( ) , is ( prelength ) ) ; m_LogFile . delete ( ) ; m_SUT . activate ( context , props ) ; setUpFileNaming ( ) ; prelength = m_LogFile . length ( ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_ERROR ) ; m_SUT . logged ( logEntry ) ; m_SUT . deactivate ( ) ; assertThat ( m_LogFile . length ( ) , greaterThan ( prelength ) ) ; }
Test setting the log level.
Test setting the log level .
// Setting key value pair // ask to log at a level too high // clear buffer and make sure that the file is the same size as it was in the beginning // start the log writer again // This is to mimic the log file created during activation. // log for the correct level // clear buffer and make sure the log file is bigger.