Search in sources :

Example 1 with ComponentStringResourceLoader

use of org.apache.wicket.resource.loader.ComponentStringResourceLoader in project wicket by apache.

the class LocalizerTest method testTwoComponents.

/**
 * Unit test for bug number [1416582] Resource loading caches wrong.
 */
@Test
public void testTwoComponents() {
    Session.get().setLocale(Locale.ENGLISH);
    MyMockPage page = new MyMockPage();
    Application.get().getResourceSettings().getStringResourceLoaders().add(new ComponentStringResourceLoader());
    Localizer localizer = Application.get().getResourceSettings().getLocalizer();
    assertEquals("value 1", localizer.getString("null", page.drop1));
    assertEquals("value 2", localizer.getString("null", page.drop2));
    Session.get().setLocale(new Locale("nl"));
    assertEquals("waarde 1", localizer.getString("null", page.drop1));
    assertEquals("waarde 2", localizer.getString("null", page.drop2));
}
Also used : Locale(java.util.Locale) ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) Test(org.junit.Test)

Example 2 with ComponentStringResourceLoader

use of org.apache.wicket.resource.loader.ComponentStringResourceLoader in project wicket by apache.

the class ApplicationSettingsTest method testDefaultStringResourceLoaderSetup.

/**
 */
@Test
public void testDefaultStringResourceLoaderSetup() {
    ResourceSettings settings = new ResourceSettings(new MockApplication());
    List<IStringResourceLoader> loaders = settings.getStringResourceLoaders();
    Assert.assertEquals("There should be 5 default loaders", 5, loaders.size());
    Assert.assertTrue("First loader one should be the component one", loaders.get(0) instanceof ComponentStringResourceLoader);
    Assert.assertTrue("Second loader should be the package one", loaders.get(1) instanceof PackageStringResourceLoader);
    Assert.assertTrue("Third loader should be the application one", loaders.get(2) instanceof ClassStringResourceLoader);
    Assert.assertTrue("Fourth loader should be the validator one", loaders.get(3) instanceof ValidatorStringResourceLoader);
    Assert.assertTrue("Fifth should be the initializer one", loaders.get(4) instanceof InitializerStringResourceLoader);
}
Also used : PackageStringResourceLoader(org.apache.wicket.resource.loader.PackageStringResourceLoader) ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) MockApplication(org.apache.wicket.mock.MockApplication) ResourceSettings(org.apache.wicket.settings.ResourceSettings) InitializerStringResourceLoader(org.apache.wicket.resource.loader.InitializerStringResourceLoader) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) ValidatorStringResourceLoader(org.apache.wicket.resource.loader.ValidatorStringResourceLoader) ClassStringResourceLoader(org.apache.wicket.resource.loader.ClassStringResourceLoader) Test(org.junit.Test)

Example 3 with ComponentStringResourceLoader

use of org.apache.wicket.resource.loader.ComponentStringResourceLoader in project wicket by apache.

the class ComponentStringResourceLoaderTest method loaderUnknownResources.

/**
 * @see org.apache.wicket.resource.StringResourceLoaderTestBase#testLoaderUnknownResources()
 */
@Override
@Test
public void loaderUnknownResources() {
    Component c = new DummyComponent("hello", tester.getApplication()) {

        private static final long serialVersionUID = 1L;
    };
    DummyPage page = new DummyPage();
    page.add(c);
    IStringResourceLoader loader = new ComponentStringResourceLoader();
    assertNull("Missing resource should return null", loader.loadStringResource(c.getClass(), "test.string.bad", Locale.getDefault(), null, null));
}
Also used : ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) Component(org.apache.wicket.Component) Test(org.junit.Test)

Example 4 with ComponentStringResourceLoader

use of org.apache.wicket.resource.loader.ComponentStringResourceLoader in project wicket by apache.

the class ComponentStringResourceLoaderTest method loadDirectFromPage.

/**
 */
@Test
public void loadDirectFromPage() {
    DummyPage p = new DummyPage();
    IStringResourceLoader loader = new ComponentStringResourceLoader();
    assertEquals("Valid resourse string should be found", "Another string", loader.loadStringResource(p.getClass(), "another.test.string", Locale.getDefault(), null, null));
}
Also used : ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) Test(org.junit.Test)

Example 5 with ComponentStringResourceLoader

use of org.apache.wicket.resource.loader.ComponentStringResourceLoader in project wicket by apache.

the class ComponentStringResourceLoaderTest method multiLevelEmbeddedComponentLoadFromComponent.

/**
 */
@Test
public void multiLevelEmbeddedComponentLoadFromComponent() {
    DummyPage p = new DummyPage();
    Panel panel = new EmptyPanel("panel");
    p.add(panel);
    DummyComponent c = new DummyComponent("hello", tester.getApplication());
    panel.add(c);
    IStringResourceLoader loader = new ComponentStringResourceLoader();
    assertEquals("Valid resourse string should be found", "Component string", loader.loadStringResource(c.getClass(), "component.string", Locale.getDefault(), null, null));
}
Also used : Panel(org.apache.wicket.markup.html.panel.Panel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) EmptyPanel(org.apache.wicket.markup.html.panel.EmptyPanel) ComponentStringResourceLoader(org.apache.wicket.resource.loader.ComponentStringResourceLoader) IStringResourceLoader(org.apache.wicket.resource.loader.IStringResourceLoader) Test(org.junit.Test)

Aggregations

ComponentStringResourceLoader (org.apache.wicket.resource.loader.ComponentStringResourceLoader)7 Test (org.junit.Test)7 IStringResourceLoader (org.apache.wicket.resource.loader.IStringResourceLoader)6 MockApplication (org.apache.wicket.mock.MockApplication)2 ResourceSettings (org.apache.wicket.settings.ResourceSettings)2 Locale (java.util.Locale)1 Component (org.apache.wicket.Component)1 EmptyPanel (org.apache.wicket.markup.html.panel.EmptyPanel)1 Panel (org.apache.wicket.markup.html.panel.Panel)1 BundleStringResourceLoader (org.apache.wicket.resource.loader.BundleStringResourceLoader)1 ClassStringResourceLoader (org.apache.wicket.resource.loader.ClassStringResourceLoader)1 InitializerStringResourceLoader (org.apache.wicket.resource.loader.InitializerStringResourceLoader)1 PackageStringResourceLoader (org.apache.wicket.resource.loader.PackageStringResourceLoader)1 ValidatorStringResourceLoader (org.apache.wicket.resource.loader.ValidatorStringResourceLoader)1