use of org.grails.buffer.GrailsPrintWriter in project grails-core by grails.
the class MockGrailsApplication method testCodecAndNoCodecGRAILS8405.
@Test
public void testCodecAndNoCodecGRAILS8405() throws IOException {
FastStringWriter target = new FastStringWriter();
GrailsWebRequest webRequest = bindMockHttpRequest();
// Initialize out and codecOut as it is done in GroovyPage.initRun
OutputEncodingStack outputStack = OutputEncodingStack.currentStack(true, target, false, true);
GrailsPrintWriter out = outputStack.getOutWriter();
webRequest.setOut(out);
GrailsPrintWriter codecOut = new CodecPrintWriter(out, getEncoder(new MockGrailsApplication(), CodecWithClosureProperties.class), registry);
// print some output
codecOut.print("hola");
codecOut.flush();
out.print("1");
out.print("2");
out.print("3");
// similar as taglib call
FastStringWriter bufferWriter = new FastStringWriter();
GrailsPrintWriter out2 = new GrailsPrintWriter(bufferWriter);
outputStack.push(out2);
out.print("4");
codecOut.print("A");
codecOut.flush();
outputStack.pop();
// add output before appending "taglib output"
out.print("added");
codecOut.print("too");
codecOut.flush();
// append "taglib output"
out.leftShift(bufferWriter.getBuffer());
// print some more output
codecOut.print("B");
codecOut.flush();
out.print("5");
codecOut.print("C");
codecOut.flush();
// clear thread local
RequestContextHolder.resetRequestAttributes();
assertEquals("-> hola <-123added-> too <-4-> A <--> B <-5-> C <-", target.getValue());
codecOut.close();
}
Aggregations