Search in sources :

Example 6 with Component

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

the class BindingSourceImplTest method expression_has_no_prefix.

@Test
public void expression_has_no_prefix() {
    BindingFactory factory = mockBindingFactory();
    Binding binding = mockBinding();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Location l = mockLocation();
    String defaultPrefix = "def";
    String description = "descrip";
    String expression = "full expression";
    train_newBinding(factory, description, container, component, expression, l, binding);
    replay();
    Map<String, BindingFactory> map = newMap();
    map.put(defaultPrefix, factory);
    BindingSource source = new BindingSourceImpl(map, interner);
    Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
    assertSame(actual, binding);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) BindingFactory(org.apache.tapestry5.services.BindingFactory) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 7 with Component

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

the class BindingSourceImplTest method expression_prefix_not_in_configuration.

@Test
public void expression_prefix_not_in_configuration() {
    BindingFactory factory = mockBindingFactory();
    Binding binding = mockBinding();
    ComponentResources container = mockComponentResources();
    ComponentResources component = mockComponentResources();
    Location l = mockLocation();
    String defaultPrefix = "def";
    String description = "descrip";
    String expression = "javascript:not-a-known-prefix";
    train_newBinding(factory, description, container, component, expression, l, binding);
    replay();
    Map<String, BindingFactory> map = newMap();
    map.put(defaultPrefix, factory);
    BindingSource source = new BindingSourceImpl(map, interner);
    Binding actual = source.newBinding(description, container, component, defaultPrefix, expression, l);
    assertSame(actual, binding);
    verify();
}
Also used : Binding(org.apache.tapestry5.Binding) BindingSource(org.apache.tapestry5.services.BindingSource) BindingFactory(org.apache.tapestry5.services.BindingFactory) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 8 with Component

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

the class MutableComponentModelImplTest method add_embedded_component_with_duplicate_id.

@Test
public void add_embedded_component_with_duplicate_id() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    model.addEmbeddedComponent("fred", "Fred1", COMPONENT_CLASS_NAME, false, null);
    try {
        model.addEmbeddedComponent("fred", "Fred2", COMPONENT_CLASS_NAME, false, null);
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Embedded component 'fred' has already been defined for component class org.example.components.Foo.");
    }
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 9 with Component

use of org.apache.tapestry5.annotations.Component 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 10 with Component

use of org.apache.tapestry5.annotations.Component 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)

Aggregations

Test (org.testng.annotations.Test)68 Component (org.apache.tapestry5.runtime.Component)43 ComponentResources (org.apache.tapestry5.ComponentResources)41 MarkupWriter (org.apache.tapestry5.MarkupWriter)18 ComponentModel (org.apache.tapestry5.model.ComponentModel)18 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)17 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)16 Binding (org.apache.tapestry5.Binding)14 Location (org.apache.tapestry5.commons.Location)14 Instantiator (org.apache.tapestry5.internal.services.Instantiator)12 Page (org.apache.tapestry5.internal.structure.Page)12 Messages (org.apache.tapestry5.commons.Messages)8 Resource (org.apache.tapestry5.commons.Resource)8 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)7 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)7 BindingFactory (org.apache.tapestry5.services.BindingFactory)7 Logger (org.slf4j.Logger)7 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)6 BindingSource (org.apache.tapestry5.services.BindingSource)6 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)5