use of org.apache.tapestry5.commons.Location 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.commons.Location 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.commons.Location 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.commons.Location in project tapestry-5 by apache.
the class AbstractPropertyOutputTest method test_null_pointer_exception_message.
@Test
public // Tests TAPESTRY-2182.
void test_null_pointer_exception_message() {
final PropertyConduit conduit = mockPropertyConduit();
final PropertyModel model = mockPropertyModel();
final Object object = new Object();
ComponentResources resources = mockComponentResources();
Location location = mockLocation();
propertyOutputFixture.inject(model, object, resources);
expect(model.getConduit()).andReturn(conduit);
expect(conduit.get(object)).andThrow(new NullPointerException());
expect(model.getPropertyName()).andReturn("wilma.occupation.address");
expect(resources.getLocation()).andReturn(location);
replay();
try {
propertyOutputFixture.readPropertyForObject();
fail("Expected a NullPointerException to be thrown.");
} catch (final TapestryException ex) {
assertEquals(ex.getMessage(), "Property 'wilma.occupation.address' contains a null value in the path.");
assertSame(ex.getLocation(), location);
assertTrue(ex.getCause() instanceof NullPointerException);
}
verify();
}
use of org.apache.tapestry5.commons.Location in project tapestry-5 by apache.
the class ComponentAssemblerImpl method createEmbeddedAssembler.
public EmbeddedComponentAssembler createEmbeddedAssembler(String embeddedId, String componentClassName, EmbeddedComponentModel embeddedModel, String mixins, Location location) {
try {
if (InternalUtils.isBlank(componentClassName)) {
throw new TapestryException("You must specify the type via t:type, the element, or @Component annotation.", location, null);
}
EmbeddedComponentAssemblerImpl embedded = new EmbeddedComponentAssemblerImpl(assemblerSource, instantiatorSource, componentClassResolver, componentClassName, getSelector(), embeddedModel, mixins, location, strictMixinParameters);
if (embeddedIdToAssembler == null)
embeddedIdToAssembler = CollectionFactory.newMap();
embeddedIdToAssembler.put(embeddedId, embedded);
if (embeddedModel != null) {
for (String publishedParameterName : embeddedModel.getPublishedParameters()) {
if (publishedParameterToEmbeddedId == null)
publishedParameterToEmbeddedId = CollectionFactory.newCaseInsensitiveMap();
String existingEmbeddedId = publishedParameterToEmbeddedId.get(publishedParameterName);
if (existingEmbeddedId != null) {
throw new TapestryException(String.format("Parameter '%s' of embedded component '%s' can not be published as a parameter of component %s, as it has previously been published by embedded component '%s'.", publishedParameterName, embeddedId, instantiator.getModel().getComponentClassName(), existingEmbeddedId), location, null);
}
publishedParameterToEmbeddedId.put(publishedParameterName, embeddedId);
}
}
return embedded;
} catch (Exception ex) {
throw new TapestryException(String.format("Failure creating embedded component '%s' of %s: %s", embeddedId, instantiator.getModel().getComponentClassName(), ExceptionUtils.toMessage(ex)), location, ex);
}
}
Aggregations