use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.
the class EnvironmentImplTest method peek_required_without_value_is_error.
@Test
public void peek_required_without_value_is_error() {
Environment e = new EnvironmentImpl();
Location l = mockLocation();
Component c = mockComponent();
replay();
e.push(Location.class, l);
e.push(Component.class, c);
try {
e.peekRequired(List.class);
unreachable();
} catch (UnknownValueException ex) {
assertEquals(ex.getMessage(), "No object of type java.util.List is available from the Environment.");
}
verify();
}
use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.
the class EnvironmentImplTest method peek_required_does_not_list_previouly_available.
@Test
public void peek_required_does_not_list_previouly_available() {
Environment e = new EnvironmentImpl();
Location l = mockLocation();
replay();
e.push(Location.class, l);
e.pop(Location.class);
try {
e.peekRequired(Location.class);
unreachable();
} catch (UnknownValueException ex) {
assertEquals(ex.getMessage(), "No object of type org.apache.tapestry5.commons.Location is available from the Environment.");
assertFalse(ex.getAvailableValues().getValues().contains("org.apache.tapestry5.ioc.Location"));
}
verify();
}
use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.
the class EnvironmentImplTest method push_and_pop.
@Test
public void push_and_pop() {
Environment e = new EnvironmentImpl();
Runnable r1 = mockRunnable();
Runnable r2 = mockRunnable();
replay();
assertNull(e.push(Runnable.class, r1));
assertSame(r1, e.peek(Runnable.class));
assertSame(r1, e.push(Runnable.class, r2));
assertSame(r2, e.peek(Runnable.class));
assertSame(r2, e.pop(Runnable.class));
assertSame(r1, e.pop(Runnable.class));
verify();
}
use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.
the class EnvironmentImplTest method peek_required_when_available.
@Test
public void peek_required_when_available() {
Environment e = new EnvironmentImpl();
Location l = mockLocation();
replay();
e.push(Location.class, l);
assertSame(l, e.peekRequired(Location.class));
verify();
}
use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.
the class BeanEditor method doPrepare.
/**
* Used to initialize the model if necessary, to instantiate the object being edited if necessary, and to push the
* BeanEditContext into the environment.
*/
void doPrepare() {
if (model == null) {
Class type = resources.getBoundType("object");
model = modelSource.createEditModel(type, overrides.getOverrideMessages());
BeanModelUtils.modify(model, add, include, exclude, reorder);
}
if (object == null) {
try {
object = model.newInstance();
} catch (Exception ex) {
String message = String.format("Exception instantiating instance of %s (for component '%s'): %s", PlasticUtils.toTypeName(model.getBeanType()), resources.getCompleteId(), ex);
throw new TapestryException(message, resources.getLocation(), ex);
}
}
BeanEditContext context = new BeanEditContextImpl(model.getBeanType());
cachedObject = object;
environment.push(BeanEditContext.class, context);
// TAP5-2101: Always provide a new BeanValidationContext
environment.push(BeanValidationContext.class, new BeanValidationContextImpl(object));
}
Aggregations