Search in sources :

Example 21 with ComponentResources

use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.

the class PropBindingFactoryTest method method_not_found_in_preamble.

@Test
public void method_not_found_in_preamble() {
    TargetBean bean = new TargetBean();
    ComponentResources resources = mockComponentResources();
    Location l = mockLocation();
    train_getComponent(resources, bean);
    replay();
    try {
        factory.newBinding("test binding", resources, null, "isThatRealBlood().value", l);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, "Class org.apache.tapestry5.internal.bindings.TargetBean does not contain a public method named 'isThatRealBlood()'");
    }
    verify();
}
Also used : ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 22 with ComponentResources

use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.

the class UploadTest method begin_render_writes_input_tag.

@Test
public void begin_render_writes_input_tag() throws Exception {
    MarkupWriter writer = createMarkupWriter();
    writer.element("form");
    FormSupport formSupport = mockFormSupport();
    ComponentResources resources = mockComponentResources();
    FieldValidator validator = mockFieldValidator();
    Request request = mockRequest();
    train_isXHR(request, false);
    formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
    validator.render(writer);
    resources.renderInformalParameters(writer);
    replay();
    Upload component = new Upload(null, null, null, null, resources, null);
    component.injectDecorator(new BaseValidationDecorator()).injectFormSupport(formSupport).injectFieldValidator(validator).injectRequest(request);
    component.beginRender(writer);
    Element element = writer.getElement();
    assertNotNull(element);
    assertEquals(element.getName(), "input");
    assertEquals(element.getAttribute("type"), "file");
    // assertEquals(element.getAttribute("name"),null);
    // assertEquals(element.getAttribute("id"),null);
    verify();
}
Also used : Element(org.apache.tapestry5.dom.Element) Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) Test(org.testng.annotations.Test)

Example 23 with ComponentResources

use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.

the class UploadTest method process_submission_extracts_value_from_decoder.

@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_extracts_value_from_decoder() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    FieldValidator validate = mockFieldValidator();
    Upload component = new Upload(null, validate, decoder, null, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("foo").anyTimes();
    support.validate(uploadedFile, resources, validate);
    replay();
    component.processSubmission("test");
    verify();
    assertSame(component.getValue(), uploadedFile);
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 24 with ComponentResources

use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.

the class UploadTest method process_submission_ignores_null_value.

@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_ignores_null_value() throws Exception {
    MultipartDecoder decoder = mockMultipartDecoder();
    UploadedFile uploadedFile = mockUploadedFile();
    ComponentResources resources = mockComponentResources();
    FieldValidationSupport support = mockFieldValidationSupport();
    FieldValidator validate = mockFieldValidator();
    Upload component = new Upload(null, validate, decoder, null, resources, support);
    expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
    expect(uploadedFile.getFileName()).andReturn("").atLeastOnce();
    support.validate(null, resources, validate);
    replay();
    component.processSubmission("test");
    verify();
    assertNull(component.getValue());
}
Also used : UploadedFile(org.apache.tapestry5.upload.services.UploadedFile) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) Test(org.testng.annotations.Test)

Example 25 with ComponentResources

use of org.apache.tapestry5.ComponentResources in project tapestry-5 by apache.

the class UploadTest method validation_decorator_invoked_inside_begin_render.

@Test
public void validation_decorator_invoked_inside_begin_render() throws Exception {
    getMocksControl().checkOrder(true);
    ComponentResources resources = mockComponentResources();
    Upload component = new Upload(null, null, null, null, resources, null);
    MarkupWriter writer = createMarkupWriter();
    writer.element("form");
    FieldValidator validator = mockFieldValidator();
    Request request = mockRequest();
    FormSupport formSupport = mockFormSupport();
    formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
    component.injectFormSupport(formSupport).injectRequest(request);
    ValidationDecorator decorator = mockValidationDecorator();
    component.injectDecorator(decorator).injectFieldValidator(validator);
    validator.render(writer);
    resources.renderInformalParameters(writer);
    decorator.insideField(component);
    train_isXHR(request, false);
    replay();
    component.beginRender(writer);
    verify();
}
Also used : Request(org.apache.tapestry5.http.services.Request) FormSupport(org.apache.tapestry5.services.FormSupport) Test(org.testng.annotations.Test)

Aggregations

ComponentResources (org.apache.tapestry5.ComponentResources)110 Test (org.testng.annotations.Test)99 Location (org.apache.tapestry5.commons.Location)34 Binding (org.apache.tapestry5.Binding)24 Messages (org.apache.tapestry5.commons.Messages)24 ComponentModel (org.apache.tapestry5.model.ComponentModel)17 FormSupport (org.apache.tapestry5.services.FormSupport)17 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)16 Component (org.apache.tapestry5.runtime.Component)15 MarkupWriter (org.apache.tapestry5.MarkupWriter)14 FieldValidator (org.apache.tapestry5.FieldValidator)13 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)13 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)13 Validator (org.apache.tapestry5.Validator)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)10 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)9 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)9 Request (org.apache.tapestry5.http.services.Request)7