Search in sources :

Example 1 with NullFieldStrategy

use of org.apache.tapestry5.NullFieldStrategy in project tapestry-5 by apache.

the class NullFieldStrategySourceImplTest method failure.

@Test
public void failure() {
    Map<String, NullFieldStrategy> configuration = CollectionFactory.newCaseInsensitiveMap();
    configuration.put("fred", mockNullFieldStrategy());
    configuration.put("barney", mockNullFieldStrategy());
    replay();
    NullFieldStrategySource source = new NullFieldStrategySourceImpl(configuration);
    try {
        source.get("wilma");
        unreachable();
    } catch (UnknownValueException ex) {
        assertEquals(ex.getMessage(), "Unrecognized name 'wilma' locating a null field strategy.");
        assertListsEquals(ex.getAvailableValues().getValues(), "barney", "fred");
    }
}
Also used : UnknownValueException(org.apache.tapestry5.commons.util.UnknownValueException) NullFieldStrategySource(org.apache.tapestry5.services.NullFieldStrategySource) NullFieldStrategy(org.apache.tapestry5.NullFieldStrategy) Test(org.testng.annotations.Test)

Example 2 with NullFieldStrategy

use of org.apache.tapestry5.NullFieldStrategy in project tapestry-5 by apache.

the class NullFieldStrategySourceImplTest method success.

@Test
public void success() {
    NullFieldStrategy strategy = mockNullFieldStrategy();
    replay();
    Map<String, NullFieldStrategy> configuration = Collections.singletonMap("strat", strategy);
    NullFieldStrategySource source = new NullFieldStrategySourceImpl(configuration);
    assertSame(source.get("strat"), strategy);
    verify();
}
Also used : NullFieldStrategySource(org.apache.tapestry5.services.NullFieldStrategySource) NullFieldStrategy(org.apache.tapestry5.NullFieldStrategy) Test(org.testng.annotations.Test)

Example 3 with NullFieldStrategy

use of org.apache.tapestry5.NullFieldStrategy in project tapestry-5 by apache.

the class TapestryModule method contributeBindingSource.

// ========================================================================
// 
// Service Builder Methods (static)
// 
// ========================================================================
// ========================================================================
// 
// Service Contribution Methods (static)
// 
// ========================================================================
/**
 * Contributes the factory for several built-in binding prefixes ("asset",
 * "block", "component", "literal", prop",
 * "nullfieldstrategy", "message", "validate", "translate", "var").
 */
public static void contributeBindingSource(MappedConfiguration<String, BindingFactory> configuration, @InjectService("PropBindingFactory") BindingFactory propBindingFactory, @InjectService("MessageBindingFactory") BindingFactory messageBindingFactory, @InjectService("ValidateBindingFactory") BindingFactory validateBindingFactory, @InjectService("TranslateBindingFactory") BindingFactory translateBindingFactory, @InjectService("AssetBindingFactory") BindingFactory assetBindingFactory, @InjectService("NullFieldStrategyBindingFactory") BindingFactory nullFieldStrategyBindingFactory, @InjectService("ContextBindingFactory") BindingFactory contextBindingFactory, @InjectService("SymbolBindingFactory") BindingFactory symbolBindingFactory) {
    configuration.add(BindingConstants.LITERAL, new LiteralBindingFactory());
    configuration.add(BindingConstants.COMPONENT, new ComponentBindingFactory());
    configuration.add(BindingConstants.VAR, new RenderVariableBindingFactory());
    configuration.add(BindingConstants.BLOCK, new BlockBindingFactory());
    configuration.add(BindingConstants.PROP, propBindingFactory);
    configuration.add(BindingConstants.MESSAGE, messageBindingFactory);
    configuration.add(BindingConstants.VALIDATE, validateBindingFactory);
    configuration.add(BindingConstants.TRANSLATE, translateBindingFactory);
    configuration.add(BindingConstants.ASSET, assetBindingFactory);
    configuration.add(BindingConstants.NULLFIELDSTRATEGY, nullFieldStrategyBindingFactory);
    configuration.add(BindingConstants.CONTEXT, contextBindingFactory);
    configuration.add(BindingConstants.SYMBOL, symbolBindingFactory);
}
Also used : LiteralBindingFactory(org.apache.tapestry5.internal.bindings.LiteralBindingFactory) BlockBindingFactory(org.apache.tapestry5.internal.bindings.BlockBindingFactory) RenderVariableBindingFactory(org.apache.tapestry5.internal.bindings.RenderVariableBindingFactory) ComponentBindingFactory(org.apache.tapestry5.internal.bindings.ComponentBindingFactory)

Example 4 with NullFieldStrategy

use of org.apache.tapestry5.NullFieldStrategy in project tapestry-5 by apache.

the class TapestryModule method contributeNullFieldStrategySource.

/**
 * Contributes strategies accessible via the {@link NullFieldStrategySource} service.
 *
 * <dl>
 * <dt>default</dt>
 * <dd>Does nothing, nulls stay null.</dd>
 * <dt>zero</dt>
 * <dd>Null values are converted to zero.</dd>
 * </dl>
 */
public static void contributeNullFieldStrategySource(MappedConfiguration<String, NullFieldStrategy> configuration) {
    configuration.add("default", new DefaultNullFieldStrategy());
    configuration.add("zero", new ZeroNullFieldStrategy());
}
Also used : DefaultNullFieldStrategy(org.apache.tapestry5.internal.DefaultNullFieldStrategy) ZeroNullFieldStrategy(org.apache.tapestry5.internal.ZeroNullFieldStrategy)

Aggregations

NullFieldStrategy (org.apache.tapestry5.NullFieldStrategy)2 NullFieldStrategySource (org.apache.tapestry5.services.NullFieldStrategySource)2 Test (org.testng.annotations.Test)2 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)1 DefaultNullFieldStrategy (org.apache.tapestry5.internal.DefaultNullFieldStrategy)1 ZeroNullFieldStrategy (org.apache.tapestry5.internal.ZeroNullFieldStrategy)1 BlockBindingFactory (org.apache.tapestry5.internal.bindings.BlockBindingFactory)1 ComponentBindingFactory (org.apache.tapestry5.internal.bindings.ComponentBindingFactory)1 LiteralBindingFactory (org.apache.tapestry5.internal.bindings.LiteralBindingFactory)1 RenderVariableBindingFactory (org.apache.tapestry5.internal.bindings.RenderVariableBindingFactory)1