mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testLogFilterSingleFromFile()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        when(context.getProperty(LogWriter.LOG_BUNDLE_FILTER_PROFILE_PREFIX_PROPERTY + 1)).
            thenReturn("green.charcoal.*:Warning");
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");

        // 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();
        
        // mock a log entry
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getBundle().getSymbolicName()).thenReturn("green.charcoal.puppies");
        when(logEntry.getMessage()).thenReturn("Test");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        
        //should not be logged because it is a debug message and the filter says not to log below Warning
        m_SUT.logged(logEntry);
        
        // this forces the flushing of the buffer.
        m_SUT.deactivate();
        // check the log file did not become larger
        assertThat(m_LogFile.length(), is(fileLength));
    }
/**
     * This tests if there is a log filter, that messages matching the filter's bundle and severity restrictions, are 
     * logged.
     */
This tests if there is a log filter, that messages matching the filter's bundle and severity restrictions, are
logged.
This tests if there is a log filter that messages matching the filter ' s bundle and severity restrictions are logged .
@Test
    public void testLogFilterSingleFromFile()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        when(context.getProperty(LogWriter.LOG_BUNDLE_FILTER_PROFILE_PREFIX_PROPERTY + 1)).
            thenReturn("green.charcoal.*:Warning");
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        m_SUT.activate(context, props);
        setUpFileNaming();
        long fileLength = m_LogFile.length();
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getBundle().getSymbolicName()).thenReturn("green.charcoal.puppies");
        when(logEntry.getMessage()).thenReturn("Test");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        when(logEntry.getTime()).thenReturn(1L);
        m_SUT.logged(logEntry);
        m_SUT.deactivate();
        assertThat(m_LogFile.length(), is(fileLength));
    }
@ Test public void testLogFilterSingleFromFile ( ) { BundleContext context = mock ( BundleContext . class ) ; Map < String , Object > props = new HashMap < String , Object > ( getComponentProperties ( ) ) ; when ( context . getProperty ( LogWriter . LOG_BUNDLE_FILTER_PROFILE_PREFIX_PROPERTY + 1 ) ) . thenReturn ( "green.charcoal.*:Warning" ) ; when ( context . getProperty ( LogWriter . LOG_DIR_PROPERTY ) ) . thenReturn ( "TempLogDir" ) ; m_SUT . activate ( context , props ) ; setUpFileNaming ( ) ; long fileLength = m_LogFile . length ( ) ; LogEntry logEntry = mock ( LogEntry . class ) ; when ( logEntry . getBundle ( ) ) . thenReturn ( m_Bundle ) ; when ( logEntry . getBundle ( ) . getSymbolicName ( ) ) . thenReturn ( "green.charcoal.puppies" ) ; when ( logEntry . getMessage ( ) ) . thenReturn ( "Test" ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_DEBUG ) ; when ( logEntry . getTime ( ) ) . thenReturn ( 1L ) ; m_SUT . logged ( logEntry ) ; m_SUT . deactivate ( ) ; assertThat ( m_LogFile . length ( ) , is ( fileLength ) ) ; }
This tests if there is a log filter, that messages matching the filter's bundle and severity restrictions, are
 logged.
This tests if there is a log filter that messages matching the filter ' s bundle and severity restrictions are logged .
// Setting key value pair // This is to mimic the log file created during activation. // testing that activation/openLogFile methods // mock a log entry //should not be logged because it is a debug message and the filter says not to log below Warning // this forces the flushing of the buffer. // check the log file did not become larger