use of org.apache.tapestry5.services.Environment 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();
}
use of org.apache.tapestry5.services.Environment 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();
}
use of org.apache.tapestry5.services.Environment 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();
}
use of org.apache.tapestry5.services.Environment 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();
}
Aggregations