Search in sources :

Example 21 with MarkupWriter

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();
}
Also used : Heartbeat(org.apache.tapestry5.services.Heartbeat) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 22 with MarkupWriter

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();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 23 with MarkupWriter

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);
}
Also used : Renderable(org.apache.tapestry5.Renderable) MarkupWriter(org.apache.tapestry5.MarkupWriter) SetupRender(org.apache.tapestry5.annotations.SetupRender)

Example 24 with MarkupWriter

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();
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) Logger(org.slf4j.Logger) MarkupWriter(org.apache.tapestry5.MarkupWriter) Test(org.testng.annotations.Test)

Example 25 with MarkupWriter

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();
}
Also used : RenderCommand(org.apache.tapestry5.runtime.RenderCommand) RenderQueue(org.apache.tapestry5.runtime.RenderQueue) Logger(org.slf4j.Logger) MarkupWriter(org.apache.tapestry5.MarkupWriter) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Aggregations

MarkupWriter (org.apache.tapestry5.MarkupWriter)72 Test (org.testng.annotations.Test)69 Element (org.apache.tapestry5.dom.Element)21 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)19 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)16 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)14 RenderQueue (org.apache.tapestry5.runtime.RenderQueue)14 ComponentResources (org.apache.tapestry5.ComponentResources)13 Link (org.apache.tapestry5.http.Link)11 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)9 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)9 FormSupport (org.apache.tapestry5.services.FormSupport)9 JSONObject (org.apache.tapestry5.json.JSONObject)7 PartialMarkupRenderer (org.apache.tapestry5.services.PartialMarkupRenderer)6 PartialMarkupRendererFilter (org.apache.tapestry5.services.PartialMarkupRendererFilter)6 Map (java.util.Map)5 FieldTranslator (org.apache.tapestry5.FieldTranslator)5 Translator (org.apache.tapestry5.Translator)5 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)5 Messages (org.apache.tapestry5.commons.Messages)5