use of org.apache.tapestry5.MarkupWriter in project tapestry-5 by apache.
the class LoopTest method non_empty_iterator.
@Test
public void non_empty_iterator() {
Heartbeat hb = mockHeartbeat();
MarkupWriter writer = mockMarkupWriter();
// Really hard to test the exact timing of all this; it will have to
// be "proven" by integration tests.
hb.begin();
EasyMock.expectLastCall().times(3);
hb.end();
EasyMock.expectLastCall().times(3);
replay();
Loop loop = new Loop();
loop.setHeartbeat(hb);
loop.setSource(Arrays.asList("alpha", "beta", "gamma"));
assertTrue(loop.setup());
assertEquals(loop.getIndex(), 0);
loop.begin(writer);
assertEquals(loop.getValue(), "alpha");
assertEquals(loop.getIndex(), 0);
assertFalse(loop.after(writer));
loop.begin(writer);
assertEquals(loop.getValue(), "beta");
assertEquals(loop.getIndex(), 1);
assertFalse(loop.after(writer));
loop.begin(writer);
assertEquals(loop.getValue(), "gamma");
assertEquals(loop.getIndex(), 2);
assertNull(loop.after(writer));
verify();
}
use of org.apache.tapestry5.MarkupWriter in project tapestry-5 by apache.
the class SelectTest method disabled_option.
@Test
public void disabled_option() throws Exception {
ValidationTracker tracker = mockValidationTracker();
// Extra cast needed for Sun compiler, not Eclipse compiler.
List<OptionModel> options = Arrays.asList((OptionModel) new OptionModelImpl("Fred", "fred") {
@Override
public boolean isDisabled() {
return true;
}
@Override
public Map<String, String> getAttributes() {
return Collections.singletonMap("class", "pixie");
}
});
Select select = new Select();
train_getInput(tracker, select, null);
replay();
select.setModel(new SelectModelImpl(null, options));
select.setValueEncoder(new StringValueEncoder());
select.setValue("barney");
select.setValidationTracker(tracker);
MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
writer.element("select");
select.options(writer);
writer.end();
assertEquals(writer.toString(), read("disabled_option.txt"));
verify();
}
use of org.apache.tapestry5.MarkupWriter in project tapestry-5 by apache.
the class RenderableProvider method setup.
@SetupRender
void setup() {
Renderable r = new Renderable() {
public void render(MarkupWriter writer) {
writer.element("strong");
writer.write("A message provided by the RenderableProvider component.");
writer.end();
}
};
environment.push(Renderable.class, r);
}
use of org.apache.tapestry5.MarkupWriter in project tapestry-5 by apache.
the class RenderQueueImplTest method run_commands.
@Test
public void run_commands() {
final RenderCommand command2 = newMock(RenderCommand.class);
RenderCommand command1 = new RenderCommand() {
public void render(MarkupWriter writer, RenderQueue queue) {
queue.push(command2);
}
};
Logger logger = mockLogger();
MarkupWriter writer = mockMarkupWriter();
RenderQueueImpl queue = new RenderQueueImpl(logger);
// There's only one check for trace enabled now.
expect(logger.isTraceEnabled(TapestryMarkers.RENDER_COMMANDS)).andReturn(false);
expect(logger.isDebugEnabled()).andReturn(true);
logger.debug(eq(TapestryMarkers.RENDER_COMMANDS), isA(String.class));
command2.render(writer, queue);
replay();
queue.push(command1);
queue.run(writer);
verify();
}
use of org.apache.tapestry5.MarkupWriter in project tapestry-5 by apache.
the class RenderQueueImplTest method command_failed.
@Test
public void command_failed() {
ComponentResources foo = mockInternalComponentResources();
ComponentResources bar = mockInternalComponentResources();
ComponentResources baz = mockInternalComponentResources();
final RuntimeException t = new RuntimeException("Oops.");
RenderCommand rc = new RenderCommand() {
public void render(MarkupWriter writer, RenderQueue queue) {
throw t;
}
@Override
public String toString() {
return "FailedCommand";
}
};
Logger logger = mockLogger();
MarkupWriter writer = mockMarkupWriter();
expect(logger.isTraceEnabled(TapestryMarkers.RENDER_COMMANDS)).andReturn(false);
expect(logger.isDebugEnabled()).andReturn(true);
logger.error("Render queue error in FailedCommand: Oops.", t);
replay();
RenderQueueImpl queue = new RenderQueueImpl(logger);
queue.startComponent(foo);
queue.startComponent(bar);
queue.endComponent();
queue.startComponent(baz);
queue.push(rc);
try {
queue.run(writer);
unreachable();
} catch (RenderQueueException ex) {
assertSame(ex.getCause(), t);
assertArraysEqual(ex.getActiveComponents(), new Object[] { foo, baz });
}
verify();
}
Aggregations