Search in sources :

Example 1 with UnknownValueException

use of org.apache.tapestry5.commons.util.UnknownValueException in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method unknown_property_id.

@Test
public void unknown_property_id() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    model.addEmpty("shrub.foo()");
    try {
        model.getById("frobozz");
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean does not contain a property with id \'frobozz\'.");
        assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName", "shrubfoo");
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Test(org.testng.annotations.Test)

Example 2 with UnknownValueException

use of org.apache.tapestry5.commons.util.UnknownValueException in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method unknown_property_name.

@Test
public void unknown_property_name() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages);
    try {
        model.get("frobozz");
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "Bean editor model for org.apache.tapestry5.internal.services.SimpleBean does not contain a property named \'frobozz\'.");
        assertListsEquals(ex.getAvailableValues().getValues(), "age", "firstName", "lastName");
    }
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) Test(org.testng.annotations.Test)

Example 3 with UnknownValueException

use of org.apache.tapestry5.commons.util.UnknownValueException in project tapestry-5 by apache.

the class ClasspathAssetAliasManagerImplTest method failure_if_path_not_in_mapped_alias_folder.

@Test
public void failure_if_path_not_in_mapped_alias_folder() {
    ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
    Resource resource = mockResource();
    expect(resource.getPath()).andReturn("org/example/icons/flag.gif").atLeastOnce();
    replay();
    try {
        manager.extractAssetAlias(resource);
        unreachable();
    } catch (UnknownValueException ex) {
        assertMessageContains(ex, "Unable to create a client URL for classpath resource org/example/icons/flag.gif");
        assertListsEquals(ex.getAvailableValues().getValues(), "com/example/mylib", "org/apache/tapestry5", "org/apache/tapestry5/internal");
    }
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) ClasspathAssetAliasManager(org.apache.tapestry5.services.ClasspathAssetAliasManager) Test(org.testng.annotations.Test)

Example 4 with UnknownValueException

use of org.apache.tapestry5.commons.util.UnknownValueException in project tapestry-5 by apache.

the class PageLoaderImpl method addParameterBindingAction.

private void addParameterBindingAction(AssemblerContext context, final EmbeddedComponentAssembler embeddedAssembler, final String parameterName, final String parameterValue, final String metaDefaultBindingPrefix, final Location location, final boolean ignoreUnmatchedFormal) {
    if (embeddedAssembler.isBound(parameterName))
        return;
    embeddedAssembler.setBound(parameterName);
    if (parameterValue.startsWith(InternalConstants.INHERIT_BINDING_PREFIX)) {
        String containerParameterName = parameterValue.substring(InternalConstants.INHERIT_BINDING_PREFIX.length());
        addInheritedBindingAction(context, parameterName, containerParameterName);
        return;
    }
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            // Because of published parameters, we have to wait until page assembly time to throw out
            // informal parameters bound to components that don't support informal parameters ...
            // otherwise we'd throw out (sometimes!) published parameters.
            final ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                if (ignoreUnmatchedFormal) {
                    return;
                }
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", pageAssembly.createdElement.peek().getCompleteId(), parameterName), null, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            final String defaultBindingPrefix = binder.getDefaultBindingPrefix(metaDefaultBindingPrefix);
            InternalComponentResources containerResources = pageAssembly.activeElement.peek().getComponentResources();
            ComponentPageElement embeddedElement = pageAssembly.createdElement.peek();
            InternalComponentResources embeddedResources = embeddedElement.getComponentResources();
            Binding binding = elementFactory.newBinding(parameterName, containerResources, embeddedResources, defaultBindingPrefix, parameterValue, location);
            binder.bind(embeddedElement, binding);
        }
    });
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) InternalComponentResources(org.apache.tapestry5.internal.InternalComponentResources) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues)

Example 5 with UnknownValueException

use of org.apache.tapestry5.commons.util.UnknownValueException in project tapestry-5 by apache.

the class PageLoaderImpl method parameter.

private void parameter(AssemblerContext context) {
    final ParameterToken token = context.next(ParameterToken.class);
    context.add(new PageAssemblyAction() {

        public void execute(PageAssembly pageAssembly) {
            String parameterName = token.name;
            ComponentPageElement element = pageAssembly.createdElement.peek();
            Location location = token.getLocation();
            BlockImpl block = new BlockImpl(location, interner.format("Parameter %s of %s", parameterName, element.getCompleteId()));
            Binding binding = new LiteralBinding(location, "block parameter " + parameterName, block);
            EmbeddedComponentAssembler embeddedAssembler = pageAssembly.embeddedAssembler.peek();
            ParameterBinder binder = embeddedAssembler.createParameterBinder(parameterName);
            if (binder == null) {
                throw new UnknownValueException(String.format("Component %s does not include a formal parameter '%s' (and does not support informal parameters).", element.getCompleteId(), parameterName), location, null, new AvailableValues("Formal parameters", embeddedAssembler.getFormalParameterNames()));
            }
            binder.bind(pageAssembly.createdElement.peek(), binding);
            pageAssembly.bodyElement.push(block);
        }
    });
    consumeToEndElementAndPopBodyElement(context);
}
Also used : LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) Binding(org.apache.tapestry5.Binding) LiteralBinding(org.apache.tapestry5.internal.bindings.LiteralBinding) UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) AvailableValues(org.apache.tapestry5.commons.util.AvailableValues) Location(org.apache.tapestry5.commons.Location)

Aggregations

UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)21 Test (org.testng.annotations.Test)11 AvailableValues (org.apache.tapestry5.commons.util.AvailableValues)9 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)4 Messages (org.apache.tapestry5.commons.Messages)4 Location (org.apache.tapestry5.commons.Location)3 Binding (org.apache.tapestry5.Binding)2 LiteralBinding (org.apache.tapestry5.internal.bindings.LiteralBinding)2 ComponentModel (org.apache.tapestry5.model.ComponentModel)2 Environment (org.apache.tapestry5.services.Environment)2 List (java.util.List)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 NullFieldStrategy (org.apache.tapestry5.NullFieldStrategy)1 Translator (org.apache.tapestry5.Translator)1 Resource (org.apache.tapestry5.commons.Resource)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Mapper (org.apache.tapestry5.func.Mapper)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 Page (org.apache.tapestry5.internal.structure.Page)1 EmbeddedComponentModel (org.apache.tapestry5.model.EmbeddedComponentModel)1