Search in sources :

Example 1 with NinjaDefault

use of ninja.NinjaDefault in project ninja by ninjaframework.

the class DiagnosticErrorRendererTest method buildAndRenderDiagnosticErrorWithHTMLEntities.

@Test
public void buildAndRenderDiagnosticErrorWithHTMLEntities() throws Exception {
    NinjaDefault ninja = Mockito.spy(new NinjaDefault());
    doReturn(Boolean.TRUE).when(ninja).isDiagnosticsEnabled();
    // build context that will have HTML entites in key spots
    when(context.getMethod()).thenReturn("GET");
    when(context.getContextPath()).thenReturn("/");
    when(context.getAttributes()).thenReturn(ImmutableMap.of("TEST-ATTR", (Object) "Attribute with < > & entities"));
    Result testResult = ninja.getInternalServerErrorResult(context, new Exception("Exception message with < > & entities"));
    // renderable in testResult is the DiagnosticError
    Assert.assertNotNull(testResult);
    Assert.assertNotNull(testResult.getRenderable());
    Assert.assertThat(testResult.getRenderable(), instanceOf(DiagnosticError.class));
    DiagnosticError de = (DiagnosticError) testResult.getRenderable();
    DiagnosticErrorRenderer renderer = DiagnosticErrorRenderer.build(context, testResult, de);
    String out = renderer.render();
    Assert.assertThat(out, containsString("Attribute with &lt; &gt; &amp; entities"));
    Assert.assertThat(out, containsString("Exception message with &lt; &gt; &amp; entities"));
}
Also used : NinjaDefault(ninja.NinjaDefault) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Result(ninja.Result) Test(org.junit.Test)

Aggregations

NinjaDefault (ninja.NinjaDefault)1 Result (ninja.Result)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1