Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BACKLOG-5408] - tests for kettle5-log4j-plugin
- Loading branch information
1 parent
42d65b4
commit 9b0aebf
Showing
8 changed files
with
434 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
55 changes: 55 additions & 0 deletions
55
plugins/kettle5-log4j-plugin/test-src/org/pentaho/di/core/logging/Log4jAppenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
package org.pentaho.di.core.logging; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import org.apache.log4j.Appender; | ||
import org.apache.log4j.spi.Filter; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
@Ignore | ||
public abstract class Log4jAppenderTest { | ||
|
||
public abstract Appender getAppender(); | ||
|
||
@Test | ||
public void addFilter() { | ||
Appender appender = getAppender(); | ||
Filter filter = mock( Filter.class ); | ||
appender.addFilter( filter ); | ||
assertThat( appender.getFilter(), is( filter ) ); | ||
} | ||
|
||
@Test | ||
public void clearFilters() { | ||
Appender appender = getAppender(); | ||
appender.addFilter( mock( Filter.class ) ); | ||
appender.clearFilters(); | ||
assertNull( appender.getFilter() ); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
plugins/kettle5-log4j-plugin/test-src/org/pentaho/di/core/logging/Log4jFileAppenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
package org.pentaho.di.core.logging; | ||
|
||
import static org.mockito.Matchers.anyBoolean; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.commons.vfs2.FileContent; | ||
import org.apache.commons.vfs2.FileObject; | ||
import org.apache.log4j.Appender; | ||
import org.apache.log4j.Layout; | ||
import org.apache.log4j.spi.LoggingEvent; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.pentaho.di.core.Const; | ||
|
||
public class Log4jFileAppenderTest extends Log4jAppenderTest { | ||
|
||
private Log4jFileAppender log4jFileAppender; | ||
|
||
private OutputStream outputStream; | ||
|
||
@Before | ||
public void before() throws IOException { | ||
outputStream = mock( OutputStream.class ); | ||
FileContent fileContent = mock( FileContent.class ); | ||
when( fileContent.getOutputStream( anyBoolean() ) ).thenReturn( outputStream ); | ||
FileObject file = mock( FileObject.class ); | ||
when( file.getContent() ).thenReturn( fileContent ); | ||
log4jFileAppender = new Log4jFileAppender( file ); | ||
} | ||
|
||
@Test | ||
public void doAppend() throws IOException { | ||
LoggingEvent loggingEvent = mock( LoggingEvent.class ); | ||
Layout testLayout = mock( Layout.class ); | ||
when( testLayout.format( loggingEvent ) ).thenReturn( "LOG_TEST_LINE" ); | ||
log4jFileAppender.setLayout( testLayout ); | ||
log4jFileAppender.doAppend( loggingEvent ); | ||
verify( outputStream ).write( ( "LOG_TEST_LINE" + Const.CR ).getBytes() ); | ||
} | ||
|
||
@Test | ||
public void close() throws IOException { | ||
log4jFileAppender.close(); | ||
verify( outputStream ).close(); | ||
} | ||
|
||
@Override | ||
public Appender getAppender() { | ||
return log4jFileAppender; | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
plugins/kettle5-log4j-plugin/test-src/org/pentaho/di/core/logging/Log4jKettleLayoutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
package org.pentaho.di.core.logging; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.TimeZone; | ||
|
||
import org.apache.log4j.spi.LoggingEvent; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class Log4jKettleLayoutTest { | ||
|
||
private TimeZone defaultTimeZone; | ||
|
||
@Before | ||
public void before() { | ||
defaultTimeZone = TimeZone.getDefault(); | ||
TimeZone.setDefault( TimeZone.getTimeZone( "UTC" ) ); | ||
} | ||
|
||
@After | ||
public void after() { | ||
TimeZone.setDefault( defaultTimeZone ); | ||
} | ||
|
||
@Test | ||
public void formatNonLogMessage_without_add_time() { | ||
Log4jKettleLayout layout = new Log4jKettleLayout( false ); | ||
String actualResult = layout.format( mock( LoggingEvent.class ) ); | ||
assertThat( actualResult, equalTo( "<null>" ) ); | ||
} | ||
|
||
@Test | ||
public void formatNonLogMessage_with_add_time() { | ||
Log4jKettleLayout layout = new Log4jKettleLayout( true ); | ||
String actualResult = layout.format( mock( LoggingEvent.class ) ); | ||
assertThat( actualResult, equalTo( "1970/01/01 00:00:00 - <null>" ) ); | ||
} | ||
|
||
@Test | ||
public void formatLogMessage_without_add_time() { | ||
Log4jKettleLayout layout = new Log4jKettleLayout( false ); | ||
LoggingEvent loggingEvent = mock( LoggingEvent.class ); | ||
LogMessage logMessage = new LogMessage( "TEST_MESSAGE", "TEST_ID", LogLevel.BASIC ); | ||
when( loggingEvent.getMessage() ).thenReturn( logMessage ); | ||
String actualResult = layout.format( loggingEvent ); | ||
assertThat( actualResult, equalTo( "TEST_MESSAGE" ) ); | ||
} | ||
|
||
@Test | ||
public void formatLogMessage_with_add_time() { | ||
Log4jKettleLayout layout = new Log4jKettleLayout( true ); | ||
LoggingEvent loggingEvent = mock( LoggingEvent.class ); | ||
LogMessage logMessage = new LogMessage( "TEST_MESSAGE", "TEST_ID", LogLevel.BASIC ); | ||
when( loggingEvent.getMessage() ).thenReturn( logMessage ); | ||
String actualResult = layout.format( loggingEvent ); | ||
assertThat( actualResult, equalTo( "1970/01/01 00:00:00 - TEST_MESSAGE" ) ); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...ins/kettle5-log4j-plugin/test-src/org/pentaho/di/core/logging/Log4jPipedAppenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/*! ****************************************************************************** | ||
* | ||
* Pentaho Data Integration | ||
* | ||
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com | ||
* | ||
******************************************************************************* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
******************************************************************************/ | ||
package org.pentaho.di.core.logging; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
import java.io.PipedOutputStream; | ||
|
||
import org.apache.log4j.Appender; | ||
import org.apache.log4j.Layout; | ||
import org.apache.log4j.spi.LoggingEvent; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.pentaho.di.core.Const; | ||
|
||
public class Log4jPipedAppenderTest extends Log4jAppenderTest { | ||
|
||
private Log4jPipedAppender log4jPipedAppender; | ||
|
||
@Before | ||
public void before() { | ||
log4jPipedAppender = new Log4jPipedAppender(); | ||
} | ||
|
||
@Test | ||
public void setPipedOutputStream() { | ||
PipedOutputStream pipedOutputStream = new PipedOutputStream(); | ||
log4jPipedAppender.setPipedOutputStream( pipedOutputStream ); | ||
assertThat( log4jPipedAppender.getPipedOutputStream(), is( pipedOutputStream ) ); | ||
} | ||
|
||
@Test | ||
public void doAppend() throws IOException { | ||
PipedOutputStream pipedOutputStream = mock( PipedOutputStream.class ); | ||
LoggingEvent loggingEvent = mock( LoggingEvent.class ); | ||
Layout testLayout = mock( Layout.class ); | ||
when( testLayout.format( loggingEvent ) ).thenReturn( "LOG_TEST_LINE" ); | ||
log4jPipedAppender.setLayout( testLayout ); | ||
log4jPipedAppender.setPipedOutputStream( pipedOutputStream ); | ||
log4jPipedAppender.doAppend( loggingEvent ); | ||
verify( pipedOutputStream ).write( ( "LOG_TEST_LINE" + Const.CR ).getBytes() ); | ||
} | ||
|
||
@Test | ||
public void close() throws IOException { | ||
PipedOutputStream pipedOutputStream = mock( PipedOutputStream.class ); | ||
log4jPipedAppender.setPipedOutputStream( pipedOutputStream ); | ||
log4jPipedAppender.close(); | ||
verify( pipedOutputStream ).close(); | ||
} | ||
|
||
@Override | ||
public Appender getAppender() { | ||
return log4jPipedAppender; | ||
} | ||
|
||
} |
Oops, something went wrong.