Search in sources :

Example 1 with ClasspathResource

use of org.apache.tapestry5.ioc.internal.util.ClasspathResource in project tapestry-5 by apache.

the class EntityManagerSourceImplTest method multiple_persistence_units_include_unlisted_classes.

@Test
public void multiple_persistence_units_include_unlisted_classes() {
    Exception exception = null;
    try {
        new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource("multiple-persistence-units-include-unlisted-classes.xml"), null, CollectionFactory.<String, PersistenceUnitConfigurer>newMap());
        fail("Exception expected");
    } catch (Exception e) {
        exception = e;
    }
    assertNotNull(exception);
    assertEquals(exception.getMessage(), "Persistence units 'TestUnit, TestUnit2' are configured to include managed classes that have not been explicitly listed. This is forbidden when multiple persistence units are used in the same application. Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) and include them explicitly.");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Test(org.testng.annotations.Test)

Example 2 with ClasspathResource

use of org.apache.tapestry5.ioc.internal.util.ClasspathResource in project tapestry-5 by apache.

the class BlockImplTest method to_string.

@Test
public void to_string() {
    Resource r = new ClasspathResource("foo/pages/MyPage.tml");
    Location l = new LocationImpl(r, 23);
    BlockImpl block = new BlockImpl(l, "test block");
    assertEquals(block.toString(), "Block[test block, at classpath:foo/pages/MyPage.tml, line 23]");
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) LocationImpl(org.apache.tapestry5.ioc.internal.util.LocationImpl) Location(org.apache.tapestry5.commons.Location) Test(org.testng.annotations.Test)

Example 3 with ClasspathResource

use of org.apache.tapestry5.ioc.internal.util.ClasspathResource in project tapestry-5 by apache.

the class ComponentMessagesSourceImplTest method subclass_inherits_base_class_messages.

@Test
public void subclass_inherits_base_class_messages() {
    ComponentModel model = mockComponentModel();
    ComponentModel parent = mockComponentModel();
    train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent");
    train_getBaseResource(model, new ClasspathResource("org/apache/tapestry5/internal/services/SubclassComponent.class"));
    train_getParentModel(model, parent);
    train_getComponentClassName(parent, SIMPLE_COMPONENT_CLASS_NAME);
    train_getBaseResource(parent, simpleComponentResource);
    train_getParentModel(parent, null);
    replay();
    forceCacheClear();
    Messages messages = source.getMessages(model, Locale.ENGLISH);
    assertEquals(messages.get("color"), "color");
    assertEquals(messages.get("framework"), "Tapestry");
    assertEquals(messages.get("source"), "SubclassComponent");
    assertEquals(messages.get("metal"), "steel");
    assertEquals(messages.get("app-catalog-source"), "AppCatalog");
    assertEquals(messages.get("app-catalog-overridden"), "Overridden by Component");
    messages = source.getMessages(model, Locale.UK);
    assertEquals(messages.get("color"), "colour");
    assertEquals(messages.get("framework"), "Tapestry");
    assertEquals(messages.get("source"), "SubclassComponent");
    assertEquals(messages.get("metal"), "aluminium");
    verify();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Messages(org.apache.tapestry5.commons.Messages) ComponentModel(org.apache.tapestry5.model.ComponentModel) Test(org.testng.annotations.Test)

Example 4 with ClasspathResource

use of org.apache.tapestry5.ioc.internal.util.ClasspathResource in project tapestry-5 by apache.

the class ComponentMessagesSourceImplTest method no_app_catalog.

@Test
public void no_app_catalog() {
    ComponentModel model = mockComponentModel();
    ComponentModel parent = mockComponentModel();
    train_getComponentClassName(model, "org.apache.tapestry5.internal.services.SubclassComponent");
    train_getBaseResource(model, new ClasspathResource("org/apache/tapestry5/internal/services/SubclassComponent.class"));
    train_getParentModel(model, parent);
    train_getComponentClassName(parent, SIMPLE_COMPONENT_CLASS_NAME);
    train_getBaseResource(parent, simpleComponentResource);
    train_getParentModel(parent, null);
    replay();
    forceCacheClear();
    Resource resource = simpleComponentResource.forFile("NoSuchAppCatalog.properties");
    List<Resource> resources = Arrays.asList(resource);
    ComponentMessagesSource source = new ComponentMessagesSourceImpl(true, resources, new PropertiesFileParserImpl(), resourceLocator, converter, componentRequestSelectorAnalyzer, threadLocale);
    Messages messages = source.getMessages(model, Locale.ENGLISH);
    assertEquals(messages.get("color"), "color");
    assertEquals(messages.get("app-catalog-source"), "[[missing key: app-catalog-source]]");
    assertEquals(messages.get("app-catalog-overridden"), "Overridden by Component");
    verify();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) PropertiesFileParserImpl(org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl) Messages(org.apache.tapestry5.commons.Messages) ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentMessagesSource(org.apache.tapestry5.services.messages.ComponentMessagesSource) Test(org.testng.annotations.Test)

Example 5 with ClasspathResource

use of org.apache.tapestry5.ioc.internal.util.ClasspathResource in project tapestry-5 by apache.

the class ComponentTemplateSourceImplTest method invalidation.

/**
 * Tests resource invalidation.
 */
@Test
public void invalidation() throws Exception {
    File rootDir = createClasspathRoot();
    URLClassLoader loader = newLoaderWithClasspathRoot(rootDir);
    ComponentModel model = mockComponentModel();
    File packageDir = new File(rootDir, "baz");
    packageDir.mkdirs();
    File f = new File(packageDir, "Biff.tml");
    f.createNewFile();
    Resource baseResource = new ClasspathResource(loader, "baz/Biff.class");
    Resource localized = baseResource.withExtension(TapestryConstants.TEMPLATE_EXTENSION);
    TemplateParser parser = mockTemplateParser();
    ComponentTemplate template = mockComponentTemplate();
    InvalidationListener listener = mockInvalidationListener();
    train_getComponentClassName(model, "baz.Biff");
    ComponentResourceLocator locator = mockLocator(model, english, localized);
    train_parseTemplate(parser, localized, template);
    replay();
    ComponentTemplateSourceImpl source = new ComponentTemplateSourceImpl(false, parser, locator, converter, componentRequestSelectorAnalyzer, threadLocale);
    source.addInvalidationListener(listener);
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    // Check for updates (which won't be found).
    source.checkForUpdates();
    // A second pass will test the caching (the
    // parser is not invoked).
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    verify();
    // Now, change the file and processInbound an UpdateEvent.
    touch(f);
    listener.objectWasInvalidated();
    replay();
    // Check for updates (which will be found).
    source.checkForUpdates();
    verify();
    // Check that the cache really is cleared.
    train_getComponentClassName(model, "baz.Biff");
    expect(locator.locateTemplate(model, english)).andReturn(localized);
    train_parseTemplate(parser, localized, template);
    replay();
    assertSame(source.getTemplate(model, Locale.ENGLISH), template);
    verify();
}
Also used : ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) URLClassLoader(java.net.URLClassLoader) ComponentModel(org.apache.tapestry5.model.ComponentModel) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) ComponentResourceLocator(org.apache.tapestry5.services.pageload.ComponentResourceLocator) ComponentTemplate(org.apache.tapestry5.internal.parser.ComponentTemplate) InvalidationListener(org.apache.tapestry5.commons.services.InvalidationListener) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)7 Test (org.testng.annotations.Test)6 Resource (org.apache.tapestry5.commons.Resource)4 ComponentModel (org.apache.tapestry5.model.ComponentModel)3 Messages (org.apache.tapestry5.commons.Messages)2 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Location (org.apache.tapestry5.commons.Location)1 InvalidationListener (org.apache.tapestry5.commons.services.InvalidationListener)1 ComponentTemplate (org.apache.tapestry5.internal.parser.ComponentTemplate)1 PropertiesFileParserImpl (org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl)1 LocationImpl (org.apache.tapestry5.ioc.internal.util.LocationImpl)1 PersistenceUnitConfigurer (org.apache.tapestry5.jpa.PersistenceUnitConfigurer)1 TapestryPersistenceUnitInfo (org.apache.tapestry5.jpa.TapestryPersistenceUnitInfo)1 ComponentMessagesSource (org.apache.tapestry5.services.messages.ComponentMessagesSource)1 PropertiesFileParser (org.apache.tapestry5.services.messages.PropertiesFileParser)1 ComponentResourceLocator (org.apache.tapestry5.services.pageload.ComponentResourceLocator)1