Search in sources :

Example 11 with Cached

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

the class MetaDataLocatorImplTest method default_matching_is_case_insensitive.

@Test
public void default_matching_is_case_insensitive() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "foo.Bar";
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, null);
    train_getContainerResources(resources, null);
    train_getPageName(resources, "foo/Bar");
    train_expandSymbols(symbolSource, value, value);
    replay();
    Map<String, String> configuration = newMap();
    configuration.put(key.toUpperCase(), value);
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 12 with Cached

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

the class MetaDataLocatorImplTest method found_in_component.

@Test
public void found_in_component() {
    ComponentResources resources = mockComponentResources();
    ComponentModel model = mockComponentModel();
    SymbolSource symbolSource = mockSymbolSource();
    ComponentModelSource modelSource = mockComponentModelSource();
    String key = "foo.bar";
    String value = "zaphod";
    String completeId = "foo.Bar:baz";
    train_getCompleteId(resources, completeId);
    train_getComponentModel(resources, model);
    train_getMeta(model, key, value);
    train_expandSymbols(symbolSource, value, value);
    replay();
    Map<String, String> configuration = Collections.emptyMap();
    MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
    // And check that it's cached:
    train_getCompleteId(resources, completeId);
    replay();
    assertSame(locator.findMeta(key, resources, String.class), value);
    verify();
}
Also used : SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) ComponentModel(org.apache.tapestry5.model.ComponentModel) MetaDataLocator(org.apache.tapestry5.services.MetaDataLocator) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 13 with Cached

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

the class AssetSourceImplTest method relative_asset.

@Test
public void relative_asset() {
    AssetFactory factory = mockAssetFactory();
    ThreadLocale threadLocale = mockThreadLocale();
    Asset asset = mockAsset();
    Resource expectedResource = baseResource.forFile("SimpleComponent_en_GB.properties");
    train_getRootResource(factory, rootResource);
    train_createAsset(factory, expectedResource, asset);
    Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    // First try creates it:
    assertSame(source.getAsset(baseResource, "SimpleComponent.properties", Locale.UK), asset);
    // Second try shows that it is cached
    assertSame(source.getAsset(baseResource, "SimpleComponent.properties", Locale.UK), asset);
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 14 with Cached

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

the class CachedWorker method adviseMethod.

private void adviseMethod(PlasticClass plasticClass, PlasticMethod method) {
    // Every instance of the clas srequires its own per-thread value. This handles the case of multiple
    // pages containing the component, or the same page containing the component multiple times.
    PlasticField cacheField = plasticClass.introduceField(PerThreadValue.class, "cache$" + method.getDescription().methodName);
    cacheField.injectComputed(new ComputedValue<PerThreadValue>() {

        public PerThreadValue get(InstanceContext context) {
            // Each instance will get a new PerThreadValue
            return perThreadManager.createValue();
        }
    });
    Cached annotation = method.getAnnotation(Cached.class);
    MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method);
    MethodAdvice advice = createAdvice(cacheField, factory);
    method.addAdvice(advice);
}
Also used : Cached(org.apache.tapestry5.annotations.Cached) PerThreadValue(org.apache.tapestry5.ioc.services.PerThreadValue)

Aggregations

Test (org.testng.annotations.Test)7 ComponentResources (org.apache.tapestry5.ComponentResources)6 SymbolSource (org.apache.tapestry5.ioc.services.SymbolSource)4 ComponentModel (org.apache.tapestry5.model.ComponentModel)4 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)4 Binding (org.apache.tapestry5.Binding)3 Cached (org.apache.tapestry5.annotations.Cached)2 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 WeakHashMap (java.util.WeakHashMap)1 Asset (org.apache.tapestry5.Asset)1 MarkupWriter (org.apache.tapestry5.MarkupWriter)1 StreamResponse (org.apache.tapestry5.StreamResponse)1