use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class AnyTest method render_with_id.
@Test
public void render_with_id() {
ComponentResources resources = mockComponentResources();
JavaScriptSupport support = mockJavaScriptSupport();
MarkupWriter writer = new MarkupWriterImpl(new DefaultMarkupModel());
resources.renderInformalParameters(writer);
String clientId = "bar";
String uniqueId = "bar_0";
expect(support.allocateClientId(clientId)).andReturn(uniqueId);
replay();
Any component = new Any();
component.inject(support, resources, "div", clientId);
component.beginRender(writer);
writer.write("content");
component.afterRender(writer);
assertEquals(writer.toString(), "<div>content</div>");
assertEquals(component.getClientId(), uniqueId);
assertEquals(writer.toString(), "<div id=\"bar_0\">content</div>");
assertEquals(component.getClientId(), uniqueId);
verify();
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class AnyTest method attempt_to_get_client_id_before_render.
@Test
public void attempt_to_get_client_id_before_render() {
ComponentResources resources = mockComponentResources();
JavaScriptSupport support = mockJavaScriptSupport();
train_getCompleteId(resources, "Foo/bar.baz");
replay();
Any component = new Any();
component.inject(support, resources, "div", null);
try {
component.getClientId();
unreachable();
} catch (IllegalStateException ex) {
assertEquals(ex.getMessage(), "Unable to provide client id for component Foo/bar.baz as it has not yet rendered.");
}
verify();
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class BeanEditorTest method refresh_bean_validation_context.
@Test
public void refresh_bean_validation_context() {
ComponentResources resources = mockComponentResources();
BeanModelSource source = mockBeanModelSource();
BeanModel model = mockBeanModel();
Environment env = mockEnvironment();
RegistrationData data = new RegistrationData();
Messages messages = mockMessages();
PropertyOverrides overrides = mockPropertyOverrides();
BeanValidationContext beanValidationContext = newMock(BeanValidationContext.class);
train_getBoundType(resources, "object", RegistrationData.class);
train_createEditModel(source, RegistrationData.class, messages, model);
train_getOverrideMessages(overrides, messages);
expect(model.newInstance()).andReturn(data);
expect(env.push(eq(BeanValidationContext.class), isA(BeanValidationContext.class))).andReturn(beanValidationContext);
expect(model.getBeanType()).andReturn(RegistrationData.class);
BeanEditContext ctxt = new BeanEditContext() {
public Class<?> getBeanClass() {
return RegistrationData.class;
}
public <T extends Annotation> T getAnnotation(Class<T> type) {
return null;
}
};
expect(env.push(eq(BeanEditContext.class), contextEq())).andReturn(ctxt);
replay();
BeanEditor component = new BeanEditor();
component.inject(resources, overrides, source, env);
component.doPrepare();
verify();
}
use of org.apache.tapestry5.annotations.Component 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.annotations.Component in project tapestry-5 by apache.
the class ResponseRendererImplTest method content_type_from_component.
@Test
public void content_type_from_component() {
RequestPageCache cache = mockRequestPageCache();
PageContentTypeAnalyzer analyzer = mockPageContentTypeAnalyzer();
Component component = mockComponent();
String pageName = "foo/bar";
Page page = mockPage();
ContentType contentType = new ContentType("zig/zag");
ComponentResources resources = mockComponentResources();
train_getComponentResources(component, resources);
train_getPageName(resources, pageName);
train_get(cache, pageName, page);
train_findContentType(analyzer, page, contentType);
replay();
ResponseRenderer renderer = new ResponseRendererImpl(cache, analyzer, null);
assertSame(renderer.findContentType(component), contentType);
verify();
}
Aggregations