Search in sources :

Example 31 with Location

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();
}
Also used : UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Environment(org.apache.tapestry5.services.Environment) Component(org.apache.tapestry5.runtime.Component) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 32 with Location

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();
}
Also used : UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Environment(org.apache.tapestry5.services.Environment) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 33 with Location

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();
}
Also used : Environment(org.apache.tapestry5.services.Environment) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 34 with Location

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();
}
Also used : PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) ComponentResources(org.apache.tapestry5.ComponentResources) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 35 with Location

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);
    }
}
Also used : TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException)

Aggregations

Location (org.apache.tapestry5.commons.Location)51 Test (org.testng.annotations.Test)41 ComponentResources (org.apache.tapestry5.ComponentResources)33 Binding (org.apache.tapestry5.Binding)25 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)21 BindingFactory (org.apache.tapestry5.services.BindingFactory)10 BindingSource (org.apache.tapestry5.services.BindingSource)6 Resource (org.apache.tapestry5.commons.Resource)4 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)4 Component (org.apache.tapestry5.runtime.Component)4 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)3 Environment (org.apache.tapestry5.services.Environment)3 Logger (org.slf4j.Logger)3 Matcher (java.util.regex.Matcher)2 QName (javax.xml.namespace.QName)2 MarkupWriter (org.apache.tapestry5.MarkupWriter)2 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)2 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)2 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)2 Messages (org.apache.tapestry5.commons.Messages)2