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();
}
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();
}
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();
}
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);
}
Aggregations