本文整理汇总了Java中org.apache.log4j.WriterAppender类的典型用法代码示例。如果您正苦于以下问题:Java WriterAppender类的具体用法?Java WriterAppender怎么用?Java WriterAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WriterAppender类属于org.apache.log4j包,在下文中一共展示了WriterAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPrintPaths
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
@Test
public void testPrintPaths() {
RestOperationMeta staticRes = UnitTestRestUtils.createRestOperationMeta("POST", "/static");
RestOperationMeta dynamicRes = UnitTestRestUtils.createRestOperationMeta("POST", "/dynamic/{id}");
MicroservicePaths paths = new MicroservicePaths();
paths.addResource(staticRes);
paths.addResource(dynamicRes);
WriterAppender appender = new WriterAppender();
Writer writer = new StringWriter();
appender.setWriter(writer);
appender.setLayout(new SimpleLayout());
Logger.getRootLogger().addAppender(appender);
paths.printPaths();
String[] lines = writer.toString().split("\n");
Assert.assertEquals("INFO - Swagger mapped \"{[/static], method=[POST], produces=[application/json]}\" onto null",
lines[0].trim());
Assert.assertEquals(
"INFO - Swagger mapped \"{[/dynamic/{id}], method=[POST], produces=[application/json]}\" onto null",
lines[1].trim());
Logger.getRootLogger().removeAppender(appender);
}
示例2: testPrint
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
@Test
public void testPrint() throws Exception {
DirectedGraph<URI, URI> graph = new DirectedSparseGraph<>();
graph.addVertex( YURI );
graph.addVertex( YUGO );
graph.addEdge( YPY, YURI, YUGO, EdgeType.DIRECTED );
Collection<URI> roots = Arrays.asList( YURI );
GraphToTreeConverter.Search search = GraphToTreeConverter.Search.DFS;
Forest<URI, URI> result = GraphToTreeConverter.convert( graph, roots, search );
Logger log = Logger.getLogger( GraphToTreeConverter.class );
StringWriter stringy = new StringWriter();
WriterAppender app = new WriterAppender( new SimpleLayout(), stringy );
log.setLevel( Level.DEBUG );
log.addAppender( app );
GraphToTreeConverter.printForest( result );
String output = stringy.toString().replaceAll( "\\s", "" );
assertEquals( "DEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/YuriDEBUG-http://semoss.va.gov/database/T44889381-85ce-43e3-893d-6267fd480660/Yugo", output );
}
示例3: testMissingSprite
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if the sprite file is
* invalid.
*/
@Test
public void testMissingSprite() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String inValidSpriteFile = "Sprite asdfsdfSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The functions to test
spriteLoader.loadSpriteSheet(inValidSpriteFile, 32, 32);
spriteLoader.getSprite(1, 0);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You are trying to use a"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例4: testNegativeDimensions
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if an incorrect position
* (on the sprite sheet) is entered.
*/
@Test
public void testNegativeDimensions() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String validSpriteFile = "peonSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The functions to test
spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
spriteLoader.getSprite(-1, -1);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You are requesting a grid position"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例5: testPositiveDimensions
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if an incorrect position
* (on the sprite sheet) is entered.
*/
@Test
public void testPositiveDimensions() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String validSpriteFile = "peonSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The functions to test
spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
spriteLoader.getSprite(6, 6);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You are requesting a grid position"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例6: testInvalidSpriteSheetDimensions
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if an invalid specified
* sprite dimension is entered.
*/
@Test
public void testInvalidSpriteSheetDimensions() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String validSpriteFile = "peonSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The functions to test
spriteLoader.loadSpriteSheet(validSpriteFile, 13, 13);
spriteLoader.getSprite(1, 0);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("WARN - Your file is not a multiple of"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例7: testValidSpriteDimensions
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that no logger message is executed if valid specified sprite
* dimensions are entered.
*/
@Test
public void testValidSpriteDimensions() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String validSpriteFile = "peonSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The functions to test
spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
spriteLoader.getSprite(1, 0);
String logMessage = outputStream.toString();
assertEquals("", logMessage);// should be empty
} finally {
LOGGER.removeAppender(appender);
}
}
示例8: testNullSpriteSheet
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if a null sprite sheet
* file name is entered (i.e. does not exist due to trolling, typos)
*/
@Test
public void testNullSpriteSheet() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Null file name
String nullSpriteFile = null;
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The function to test
spriteLoader.loadSpriteSheet(nullSpriteFile, 32, 32);
assertNull(nullSpriteFile);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - Could not load file"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例9: testInvalidSpriteSheet
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the right logger message is executed if an invalid sprite
* sheet file name is entered (i.e. does not exist due to trolling, typos)
*/
@Test
public void testInvalidSpriteSheet() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Invalid file name
String invalidSpriteFile = "invalid name";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The function to test
spriteLoader.loadSpriteSheet(invalidSpriteFile, 32, 32);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - Could not load file"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例10: testValidSpriteSheet
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that no logger message is executed if a valid sprite sheet is
* entered
*/
@Test
public void testValidSpriteSheet() {
// Set up logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
// Valid file name
String validSpriteFile = "peonSheet";
SpriteLoader spriteLoader = new SpriteLoader();
try {
// The function to test
spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
assertNotNull(validSpriteFile);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertEquals("", logMessage);// should be empty
} finally {
LOGGER.removeAppender(appender);
}
}
示例11: validFrameInitialisation
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that no logger message is executed for a valid frame setup.
*/
@Test
public void validFrameInitialisation() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
Image mockSprite = mock(Image.class);
try {
// The functions to test
frame = new Frame(mockSprite, 10);
assertNotNull(frame.getFrame());
assertTrue(frame.getDuration() == 10);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertEquals("", logMessage);
} finally {
LOGGER.removeAppender(appender);
}
}
示例12: validGetters
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that getters are not null if there is a valid Frame initilisation.
*/
@Test
public void validGetters() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
Image mockSprite = mock(Image.class);
try {
// The functions to test
frame = new Frame(mockSprite, 10);
assertNotNull(frame.getFrame());
assertNotNull(frame.getDuration());
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertEquals("", logMessage);
} finally {
LOGGER.removeAppender(appender);
}
}
示例13: inValidFrame
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the appropriate error message is displayed if the frame image
* is null.
*/
@Test
public void inValidFrame() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
try {
// The functions to test
frame = new Frame(null, 10);
assertNull(frame.getFrame());
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You cannot have null frames"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例14: inValidDuration
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the appropriate logger message is executed if the duration is
* less than or equal to 0.
*/
@Test
public void inValidDuration() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
Image mockSprite = mock(Image.class);
try {
// The functions to test
frame = new Frame(mockSprite, 0);
assertTrue(frame.getDuration() == 0);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You cannot have a duration equal to or less than 0"));
} finally {
LOGGER.removeAppender(appender);
}
}
示例15: invalidSettersDuration
import org.apache.log4j.WriterAppender; //导入依赖的package包/类
/**
* Tests that the appropriate logger message is executed if the duration is
* set to be less than or equal to 0.
*/
@Test
public void invalidSettersDuration() {
// Set up of logger retrieval
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Layout layout = new SimpleLayout();
Appender appender = new WriterAppender(layout, outputStream);
LOGGER.addAppender(appender);
Image mockSprite = mock(Image.class);
frame = new Frame(mockSprite, 10);
try {
// The functions to test
assertTrue(frame.getDuration() == 10);
frame.setDuration(-1);
assertTrue(frame.getDuration() == 10);
String logMessage = outputStream.toString();
assertNotNull(logMessage);
assertTrue(logMessage.contains("ERROR - You cannot have a duration"));
} finally {
LOGGER.removeAppender(appender);
}
}