mil.dod.th.ose.logging/test/mil/dod/th/ose/logging/TestLogWriter.java
@Test
    public void testLogFiltersMultiples()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        //force more frequent flushing
        props.put("fileBufferSize", 1);
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        
        //create a log filter
        LogFilter filterA = createFilter("my.bundle.*", 3);
        LogFilter filterB = createFilter("your.bundle.kittens.*", 1);
        LogFilter filterC = createFilter("their.giraffe.cam.*", 3);
        LogFilter filterD = createFilter("their.giraffe.cam.guppy", 1);

        // Setting key value pair
        m_SUT.activate(context, props);
        
        //set log filters
        m_SUT.setLogFilter(filterA);
        m_SUT.setLogFilter(filterB);
        m_SUT.setLogFilter(filterC);
        m_SUT.setLogFilter(filterD);
        
        // This is to mimic the log file created during activation.
        setUpFileNaming();

        // initial file size
        long fileLength = m_LogFile.length();
        
        // mock a log entry
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getMessage()).thenReturn("Test");
        when(logEntry.getTime()).thenReturn(1L);
        
        //test filter A
        when(logEntry.getBundle().getSymbolicName()).thenReturn("my.bundle");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        m_SUT.logged(logEntry);
        
        long filePostALength = m_LogFile.length();
        
        //test filter B
        when(logEntry.getBundle().getSymbolicName()).thenReturn("your.bundle.kittens.fuzzy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);
        
        long filePostBLength = m_LogFile.length();

        //test filter D and C, should be logged, because Filter C covers the bundle's name,
        //even though D is more specific and higher severity, go with lower severity
        when(logEntry.getBundle().getSymbolicName()).thenReturn("their.giraffe.cam.guppy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_WARNING);
        m_SUT.logged(logEntry);

        long filePostCLength = m_LogFile.length();
        
        //unset filter C and retry
        m_SUT.unsetLogFilter(filterC);
        
        //shouldn't log this time
        when(logEntry.getBundle().getSymbolicName()).thenReturn("their.giraffe.cam.guppy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_WARNING);
        m_SUT.logged(logEntry);

        long filePostDLength = m_LogFile.length();
        
        // this forces the flushing of the buffer.
        m_SUT.deactivate();
        
        // check the log file became larger due the entries being logged
        assertThat(filePostALength, is(fileLength));
        assertThat(filePostBLength, greaterThan(filePostALength));
        assertThat(filePostCLength, greaterThan(filePostBLength));
        assertThat(filePostDLength, is(filePostCLength));
    }
/**
     * This tests if there is are log filters, that messages matching a filter's bundle and severity restriction are 
     * logged when appropriate.
     */
This tests if there is are log filters, that messages matching a filter's bundle and severity restriction are
logged when appropriate.
This tests if there is are log filters that messages matching a filter ' s bundle and severity restriction are logged when appropriate .
@Test
    public void testLogFiltersMultiples()
    {
        BundleContext context = mock(BundleContext.class);
        Map<String, Object> props = new HashMap<String, Object>(getComponentProperties());
        props.put("fileBufferSize", 1);
        when(context.getProperty(LogWriter.LOG_DIR_PROPERTY)).thenReturn("TempLogDir");
        LogFilter filterA = createFilter("my.bundle.*", 3);
        LogFilter filterB = createFilter("your.bundle.kittens.*", 1);
        LogFilter filterC = createFilter("their.giraffe.cam.*", 3);
        LogFilter filterD = createFilter("their.giraffe.cam.guppy", 1);
        m_SUT.activate(context, props);
        m_SUT.setLogFilter(filterA);
        m_SUT.setLogFilter(filterB);
        m_SUT.setLogFilter(filterC);
        m_SUT.setLogFilter(filterD);
        setUpFileNaming();
        long fileLength = m_LogFile.length();
        LogEntry logEntry = mock(LogEntry.class);
        when(logEntry.getBundle()).thenReturn(m_Bundle);
        when(logEntry.getMessage()).thenReturn("Test");
        when(logEntry.getTime()).thenReturn(1L);
        when(logEntry.getBundle().getSymbolicName()).thenReturn("my.bundle");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_DEBUG);
        m_SUT.logged(logEntry);
        long filePostALength = m_LogFile.length();
        when(logEntry.getBundle().getSymbolicName()).thenReturn("your.bundle.kittens.fuzzy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_ERROR);
        m_SUT.logged(logEntry);
        long filePostBLength = m_LogFile.length();
        when(logEntry.getBundle().getSymbolicName()).thenReturn("their.giraffe.cam.guppy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_WARNING);
        m_SUT.logged(logEntry);
        long filePostCLength = m_LogFile.length();
        m_SUT.unsetLogFilter(filterC);
        when(logEntry.getBundle().getSymbolicName()).thenReturn("their.giraffe.cam.guppy");
        when(logEntry.getLevel()).thenReturn(LogService.LOG_WARNING);
        m_SUT.logged(logEntry);
        long filePostDLength = m_LogFile.length();
        m_SUT.deactivate();
        assertThat(filePostALength, is(fileLength));
        assertThat(filePostBLength, greaterThan(filePostALength));
        assertThat(filePostCLength, greaterThan(filePostBLength));
        assertThat(filePostDLength, is(filePostCLength));
    }
@ Test public void testLogFiltersMultiples ( ) { BundleContext context = mock ( BundleContext . class ) ; Map < String , Object > props = new HashMap < String , Object > ( getComponentProperties ( ) ) ; props . put ( "fileBufferSize" , 1 ) ; when ( context . getProperty ( LogWriter . LOG_DIR_PROPERTY ) ) . thenReturn ( "TempLogDir" ) ; LogFilter filterA = createFilter ( "my.bundle.*" , 3 ) ; LogFilter filterB = createFilter ( "your.bundle.kittens.*" , 1 ) ; LogFilter filterC = createFilter ( "their.giraffe.cam.*" , 3 ) ; LogFilter filterD = createFilter ( "their.giraffe.cam.guppy" , 1 ) ; m_SUT . activate ( context , props ) ; m_SUT . setLogFilter ( filterA ) ; m_SUT . setLogFilter ( filterB ) ; m_SUT . setLogFilter ( filterC ) ; m_SUT . setLogFilter ( filterD ) ; setUpFileNaming ( ) ; long fileLength = m_LogFile . length ( ) ; LogEntry logEntry = mock ( LogEntry . class ) ; when ( logEntry . getBundle ( ) ) . thenReturn ( m_Bundle ) ; when ( logEntry . getMessage ( ) ) . thenReturn ( "Test" ) ; when ( logEntry . getTime ( ) ) . thenReturn ( 1L ) ; when ( logEntry . getBundle ( ) . getSymbolicName ( ) ) . thenReturn ( "my.bundle" ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_DEBUG ) ; m_SUT . logged ( logEntry ) ; long filePostALength = m_LogFile . length ( ) ; when ( logEntry . getBundle ( ) . getSymbolicName ( ) ) . thenReturn ( "your.bundle.kittens.fuzzy" ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_ERROR ) ; m_SUT . logged ( logEntry ) ; long filePostBLength = m_LogFile . length ( ) ; when ( logEntry . getBundle ( ) . getSymbolicName ( ) ) . thenReturn ( "their.giraffe.cam.guppy" ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_WARNING ) ; m_SUT . logged ( logEntry ) ; long filePostCLength = m_LogFile . length ( ) ; m_SUT . unsetLogFilter ( filterC ) ; when ( logEntry . getBundle ( ) . getSymbolicName ( ) ) . thenReturn ( "their.giraffe.cam.guppy" ) ; when ( logEntry . getLevel ( ) ) . thenReturn ( LogService . LOG_WARNING ) ; m_SUT . logged ( logEntry ) ; long filePostDLength = m_LogFile . length ( ) ; m_SUT . deactivate ( ) ; assertThat ( filePostALength , is ( fileLength ) ) ; assertThat ( filePostBLength , greaterThan ( filePostALength ) ) ; assertThat ( filePostCLength , greaterThan ( filePostBLength ) ) ; assertThat ( filePostDLength , is ( filePostCLength ) ) ; }
This tests if there is are log filters, that messages matching a filter's bundle and severity restriction are
 logged when appropriate.
This tests if there is are log filters that messages matching a filter ' s bundle and severity restriction are logged when appropriate .
//force more frequent flushing //create a log filter // Setting key value pair //set log filters // This is to mimic the log file created during activation. // initial file size // mock a log entry //test filter A //test filter B //test filter D and C, should be logged, because Filter C covers the bundle's name, //even though D is more specific and higher severity, go with lower severity //unset filter C and retry //shouldn't log this time // this forces the flushing of the buffer. // check the log file became larger due the entries being logged