Search in sources :

Example 1 with Form

use of org.apache.tapestry5.corelib.components.Form in project tapestry-5 by apache.

the class MultipartServletRequestFilterTest method multipartRequestIsDecoded.

@Test
public void multipartRequestIsDecoded() throws Exception {
    MultipartDecoder decoder = newMock(MultipartDecoder.class);
    HttpServletRequest request = mockHttpServletRequest();
    HttpServletRequest decodedRequest = mockHttpServletRequest();
    HttpServletResponse response = mockHttpServletResponse();
    HttpServletRequestHandler handler = newMock(HttpServletRequestHandler.class);
    MultipartServletRequestFilter filter = new MultipartServletRequestFilter(decoder);
    expect(request.getMethod()).andReturn("post");
    expect(request.getContentType()).andReturn("multipart/form");
    expect(decoder.decode(request)).andReturn(decodedRequest);
    expect(handler.service(decodedRequest, response)).andReturn(true);
    replay();
    boolean isHandled = filter.service(request, response, handler);
    assertTrue(isHandled);
    verify();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MultipartDecoder(org.apache.tapestry5.upload.services.MultipartDecoder) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequestHandler(org.apache.tapestry5.http.services.HttpServletRequestHandler) Test(org.testng.annotations.Test)

Example 2 with Form

use of org.apache.tapestry5.corelib.components.Form 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 3 with Form

use of org.apache.tapestry5.corelib.components.Form 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)

Example 4 with Form

use of org.apache.tapestry5.corelib.components.Form in project tapestry-5 by apache.

the class BeanModelImpl method reorder.

public BeanModel<T> reorder(String... propertyNames) {
    List<String> remainingPropertyNames = CollectionFactory.newList(this.propertyNames);
    List<String> reorderedPropertyNames = CollectionFactory.newList();
    for (String name : propertyNames) {
        PropertyModel model = get(name);
        // Get the canonical form (which may differ from name in terms of case)
        String canonical = model.getPropertyName();
        reorderedPropertyNames.add(canonical);
        remainingPropertyNames.remove(canonical);
    }
    this.propertyNames.clear();
    this.propertyNames.addAll(reorderedPropertyNames);
    // Any unspecified names are ordered to the end. Don't want them? Remove them instead.
    this.propertyNames.addAll(remainingPropertyNames);
    return this;
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel)

Example 5 with Form

use of org.apache.tapestry5.corelib.components.Form in project tapestry-5 by apache.

the class FormTest method record_error.

@Test
public void record_error() {
    ValidationTracker tracker = mockValidationTracker();
    String message = "A recorded message.";
    tracker.recordError(message);
    replay();
    Form form = new Form();
    form.setTracker(tracker);
    form.recordError(message);
    verify();
}
Also used : ValidationTracker(org.apache.tapestry5.ValidationTracker) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)12 Element (org.apache.tapestry5.dom.Element)7 FormSupport (org.apache.tapestry5.services.FormSupport)7 FieldValidator (org.apache.tapestry5.FieldValidator)4 ComponentResources (org.apache.tapestry5.ComponentResources)3 Validator (org.apache.tapestry5.Validator)3 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)3 Messages (org.apache.tapestry5.commons.Messages)3 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)3 Request (org.apache.tapestry5.http.services.Request)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 Component (org.apache.tapestry5.runtime.Component)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ValidationTracker (org.apache.tapestry5.ValidationTracker)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 ComponentActionSink (org.apache.tapestry5.corelib.internal.ComponentActionSink)2 Document (org.apache.tapestry5.dom.Document)2 Link (org.apache.tapestry5.http.Link)2 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)2 IdAllocator (org.apache.tapestry5.ioc.util.IdAllocator)2