Search in sources :

Example 6 with Resource

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

the class MutableComponentModelImplTest method get_persistent_field_names_reflects_parent_model.

@Test
public void get_persistent_field_names_reflects_parent_model() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel parent = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    assertEquals(parent.setFieldPersistenceStrategy("wilma", "session"), "wilma");
    MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, parent, false, null);
    assertEquals(model.setFieldPersistenceStrategy("fred", "session"), "fred");
    assertEquals(model.setFieldPersistenceStrategy("barney", "client"), "barney");
    assertEquals(model.getPersistentFieldNames(), Arrays.asList("barney", "fred", "wilma"));
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 7 with Resource

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

the class MutableComponentModelImplTest method set_and_get_meta.

@Test
public void set_and_get_meta() {
    Resource r = mockResource();
    Logger logger = mockLogger();
    replay();
    MutableComponentModel model = new MutableComponentModelImpl(CLASS_NAME, logger, r, null, false, null);
    model.setMeta("fred", "flintstone");
    model.setMeta("barney", "rubble");
    assertEquals(model.getMeta("fred"), "flintstone");
    assertEquals(model.getMeta("barney"), "rubble");
    // Ensure case insensitive:
    assertEquals(model.getMeta("FRED"), "flintstone");
    assertEquals(model.getMeta("BARNEY"), "rubble");
    verify();
}
Also used : Resource(org.apache.tapestry5.commons.Resource) MutableComponentModel(org.apache.tapestry5.model.MutableComponentModel) Logger(org.slf4j.Logger) Test(org.testng.annotations.Test)

Example 8 with Resource

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

the class AssetSourceImplTest method get_classpath_asset.

@Test
public void get_classpath_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.getClasspathAsset("org/apache/tapestry5/internal/services/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 9 with Resource

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

the class AssetSourceImplTest method get_expanded_asset.

@Test
public void get_expanded_asset() {
    AssetFactory factory = mockAssetFactory();
    Asset asset = mockAsset();
    SymbolSource symbolSource = mockSymbolSource();
    Resource expectedResource = baseResource.forFile("SimpleComponent.properties");
    train_getRootResource(factory, rootResource);
    train_createAsset(factory, expectedResource, asset);
    train_expandSymbols(symbolSource, "${path}/SimpleComponent.properties", "org/apache/tapestry5/internal/services/SimpleComponent.properties");
    Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
    replay();
    AssetSource source = new AssetSourceImpl(null, configuration, symbolSource, null, tracker);
    // First try creates it:
    assertSame(source.getExpandedAsset("${path}/SimpleComponent.properties"), asset);
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) 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 10 with Resource

use of org.apache.tapestry5.commons.Resource 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)

Aggregations

Resource (org.apache.tapestry5.commons.Resource)78 Test (org.testng.annotations.Test)62 MutableComponentModel (org.apache.tapestry5.model.MutableComponentModel)38 Logger (org.slf4j.Logger)38 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)16 Asset (org.apache.tapestry5.Asset)14 ComponentModel (org.apache.tapestry5.model.ComponentModel)10 MutableEmbeddedComponentModel (org.apache.tapestry5.model.MutableEmbeddedComponentModel)10 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)6 AssetFactory (org.apache.tapestry5.services.AssetFactory)6 IOException (java.io.IOException)5 AssetSource (org.apache.tapestry5.services.AssetSource)5 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)5 Context (org.apache.tapestry5.http.services.Context)4 BeginRender (org.apache.tapestry5.annotations.BeginRender)3 Location (org.apache.tapestry5.commons.Location)3 AbstractResource (org.apache.tapestry5.ioc.internal.util.AbstractResource)3 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)3 ClasspathAssetAliasManager (org.apache.tapestry5.services.ClasspathAssetAliasManager)3 StreamableResource (org.apache.tapestry5.services.assets.StreamableResource)3