Example usage for org.apache.wicket.util.tester Result wasFailed

List of usage examples for org.apache.wicket.util.tester Result wasFailed

Introduction

In this page you can find the example usage for org.apache.wicket.util.tester Result wasFailed.

Prototype

public boolean wasFailed() 

Source Link

Document

Returns true if the Result was a failure.

Usage

From source file:org.geoserver.gwc.web.GWCSettingsPageTest.java

License:Open Source License

@Test
public void testEnableDisableInnerCaching() throws Exception {
    GWC gwc = GWC.get();/* ww  w .ja va 2s.c om*/
    GWCConfig config = gwc.getConfig();
    // Creation of a new page to test
    GWCSettingsPage page = new GWCSettingsPage();
    // Start the page
    tester.startPage(page);
    // Ensure the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);
    // Ensure the component blobstores belongs to the BlobStorePanel class
    tester.assertComponent("form:cachingOptionsPanel:container:configs:blobstores",
            InMemoryBlobStorePanel.class);

    // Selection of the form tests
    FormTester form = tester.newFormTester("form");
    form.setValue("cachingOptionsPanel:container:configs:blobstores:innerCachingEnabled", true);
    // Check that the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);
    // Save the changes
    form.submit("submit");
    // Check no exception has been thrown
    tester.assertNoErrorMessage();
    // Check the GWCConfig
    config = gwc.getConfig();
    assertTrue(config.isInnerCachingEnabled());

    // Start the page
    tester.startPage(new GWCSettingsPage());
    // Ensure the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);

    // Check if the Cache Provider is GuavaCacheProvider
    tester.assertComponent("form:cachingOptionsPanel:container:configs:blobstores:container:caches",
            DropDownChoice.class);
    DropDownChoice<String> choice = (DropDownChoice<String>) tester.getComponentFromLastRenderedPage(
            "form:cachingOptionsPanel:container:configs:blobstores:container:caches");
    assertTrue(choice.getChoices().get(0).equalsIgnoreCase(GuavaCacheProvider.class.toString()));

    // Ensure that the other fields are enabled
    Component comp1 = tester.getComponentFromLastRenderedPage(
            "form:cachingOptionsPanel:container:configs:blobstores:container:cacheConfContainer:hardMemoryLimit");
    Component comp2 = tester.getComponentFromLastRenderedPage(
            "form:cachingOptionsPanel:container:configs:blobstores:container:cacheConfContainer:concurrencyLevel");

    assertTrue(comp1.isEnabled());
    assertTrue(comp2.isEnabled());

    // Selection of the form tests
    form = tester.newFormTester("form");
    form.setValue("cachingOptionsPanel:container:configs:blobstores:container:persistenceEnabled", true);
    form.setValue(
            "cachingOptionsPanel:container:configs:blobstores:container:cacheConfContainer:hardMemoryLimit",
            1 + "");
    form.setValue(
            "cachingOptionsPanel:container:configs:blobstores:container:cacheConfContainer:concurrencyLevel",
            1 + "");
    // Check that the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);
    // Save the changes
    form.submit("submit");
    // Check no exception has been thrown
    tester.assertNoErrorMessage();
    // Check the GWCConfig
    config = gwc.getConfig();
    assertTrue(config.isPersistenceEnabled());
    assertEquals(config.getCacheConfigurations().get(GuavaCacheProvider.class.toString()).getConcurrencyLevel(),
            1);
    assertEquals(config.getCacheConfigurations().get(GuavaCacheProvider.class.toString()).getHardMemoryLimit(),
            1);

    // Start the page
    tester.startPage(new GWCSettingsPage());
    // Ensure the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);

    // Selection of the form tests
    form = tester.newFormTester("form");
    form.setValue("cachingOptionsPanel:container:configs:blobstores:innerCachingEnabled", false);
    // Save the changes
    form.submit("submit");

    // Start the page
    tester.startPage(new GWCSettingsPage());
    // Ensure the page is correctly rendered
    tester.assertRenderedPage(GWCSettingsPage.class);
    Result res = tester
            .isVisible("form:cachingOptionsPanel:container:configs:blobstores:container:persistenceEnabled");
    assertTrue(res.wasFailed());
    // Check the GWCConfig
    config = gwc.getConfig();
    assertFalse(config.isInnerCachingEnabled());
}