Search in sources :

Example 6 with PropertyOverrides

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

the class BeanEditorTest method beaneditcontext_popped_from_environment.

@Test
public void beaneditcontext_popped_from_environment() {
    ComponentResources resources = mockComponentResources();
    BeanModelSource source = mockBeanModelSource();
    Environment env = mockEnvironment();
    PropertyOverrides overrides = mockPropertyOverrides();
    expect(env.pop(BeanEditContext.class)).andReturn(null);
    expect(env.pop(BeanValidationContext.class)).andReturn(null);
    replay();
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    component.cleanupEnvironment();
    verify();
}
Also used : BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Environment(org.apache.tapestry5.services.Environment) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 7 with PropertyOverrides

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

the class BeanEditorTest method beaneditcontext_pushed_to_environment.

@Test
public void beaneditcontext_pushed_to_environment() {
    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(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);
    expect(env.push(eq(BeanValidationContext.class), isA(BeanValidationContext.class))).andReturn(beanValidationContext);
    replay();
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    component.doPrepare();
    verify();
}
Also used : RegistrationData(org.apache.tapestry5.integration.app1.data.RegistrationData) BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) BeanValidationContext(org.apache.tapestry5.internal.BeanValidationContext) Environment(org.apache.tapestry5.services.Environment) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) Annotation(java.lang.annotation.Annotation) ComponentResources(org.apache.tapestry5.ComponentResources) BeanEditContext(org.apache.tapestry5.services.BeanEditContext) Test(org.testng.annotations.Test)

Example 8 with PropertyOverrides

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

the class BeanEditorTest method object_created_as_needed.

@Test
public void object_created_as_needed() {
    ComponentResources resources = mockComponentResources();
    BeanModelSource source = mockBeanModelSource();
    BeanModel model = mockBeanModel();
    RegistrationData data = new RegistrationData();
    Messages messages = mockMessages();
    PropertyOverrides overrides = mockPropertyOverrides();
    Environment env = EasyMock.createNiceMock(Environment.class);
    train_getBoundType(resources, "object", RegistrationData.class);
    train_createEditModel(source, RegistrationData.class, messages, model);
    train_getOverrideMessages(overrides, messages);
    expect(model.newInstance()).andReturn(data);
    expect(model.getBeanType()).andReturn(RegistrationData.class);
    replay();
    EasyMock.replay(env);
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    component.doPrepare();
    assertSame(component.getObject(), data);
    verify();
}
Also used : RegistrationData(org.apache.tapestry5.integration.app1.data.RegistrationData) BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Environment(org.apache.tapestry5.services.Environment) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 9 with PropertyOverrides

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

the class BeanEditorTest method object_can_not_be_instantiated.

@Test
public void object_can_not_be_instantiated() {
    ComponentResources resources = mockComponentResources();
    BeanModelSource source = mockBeanModelSource();
    BeanModel model = mockBeanModel();
    Location l = mockLocation();
    Throwable exception = new RuntimeException("Fall down go boom.");
    PropertyOverrides overrides = mockPropertyOverrides();
    Messages messages = mockMessages();
    Environment env = EasyMock.createNiceMock(Environment.class);
    train_getOverrideMessages(overrides, messages);
    train_getBoundType(resources, "object", Runnable.class);
    train_createEditModel(source, Runnable.class, messages, model);
    expect(model.newInstance()).andThrow(exception);
    train_getCompleteId(resources, "Foo.bar");
    train_getLocation(resources, l);
    expect(model.getBeanType()).andReturn(Runnable.class);
    replay();
    EasyMock.replay(env);
    BeanEditor component = new BeanEditor();
    component.inject(resources, overrides, source, env);
    try {
        component.doPrepare();
        unreachable();
    } catch (TapestryException ex) {
        assertMessageContains(ex, "Exception instantiating instance of java.lang.Runnable (for component \'Foo.bar\'):");
        assertSame(ex.getLocation(), l);
    }
    verify();
}
Also used : BeanModelSource(org.apache.tapestry5.beanmodel.services.BeanModelSource) Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Environment(org.apache.tapestry5.services.Environment) PropertyOverrides(org.apache.tapestry5.PropertyOverrides) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Aggregations

ComponentResources (org.apache.tapestry5.ComponentResources)9 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)9 Test (org.testng.annotations.Test)8 Messages (org.apache.tapestry5.commons.Messages)7 BeanModelSource (org.apache.tapestry5.beanmodel.services.BeanModelSource)5 Environment (org.apache.tapestry5.services.Environment)5 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)4 RegistrationData (org.apache.tapestry5.integration.app1.data.RegistrationData)3 Annotation (java.lang.annotation.Annotation)2 Block (org.apache.tapestry5.Block)2 Location (org.apache.tapestry5.commons.Location)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)2 BeanEditContext (org.apache.tapestry5.services.BeanEditContext)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1