Issue #1475 - more tests for bad ContextHandler.logger creation

This commit is contained in:
Joakim Erdfelt 2017-04-14 12:53:25 -07:00
parent ccfe579a55
commit e598f5da14
2 changed files with 73 additions and 6 deletions

View File

@ -816,10 +816,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
}
}
if (StringUtil.isNotBlank(log_name))
if (StringUtil.isBlank(log_name))
{
// try hex of hashcode
log_name = Integer.toHexString(hashCode());
// an empty context path is the ROOT context
log_name = "ROOT";
}
}

View File

@ -458,15 +458,82 @@ public class ContextHandlerTest
}
@Test
public void testLogName() throws Exception
public void testLogNameFromDisplayName() throws Exception
{
ContextHandler handler = new ContextHandler();
handler.setServer(new Server());
handler.setDisplayName(".");
handler.setDisplayName("An Interesting Project: app.tast.ic");
try
{
handler.start();
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName()));
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".An_Interesting_Project__app_tast_ic"));
}
finally
{
handler.stop();
}
}
@Test
public void testLogNameFromContextPath_Deep() throws Exception
{
ContextHandler handler = new ContextHandler();
handler.setServer(new Server());
handler.setContextPath("/app/tast/ic");
try
{
handler.start();
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".app_tast_ic"));
}
finally
{
handler.stop();
}
}
@Test
public void testLogNameFromContextPath_Root() throws Exception
{
ContextHandler handler = new ContextHandler();
handler.setServer(new Server());
handler.setContextPath("");
try
{
handler.start();
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT"));
}
finally
{
handler.stop();
}
}
@Test
public void testLogNameFromContextPath_Undefined() throws Exception
{
ContextHandler handler = new ContextHandler();
handler.setServer(new Server());
try
{
handler.start();
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT"));
}
finally
{
handler.stop();
}
}
@Test
public void testLogNameFromContextPath_Empty() throws Exception
{
ContextHandler handler = new ContextHandler();
handler.setServer(new Server());
handler.setContextPath("");
try
{
handler.start();
assertThat("handler.get", handler.getLogger().getName(), is(ContextHandler.class.getName() + ".ROOT"));
}
finally
{