/** * Shorthand convenience method to get the Configuration instance. * * @return the Configuration instance. */ private static Configuration get() { return Config.getInstance(); }
/** * Resets the configuration back to the default internal configuration. All configuration changes which have been * made will be lost. This method is primarily intended for unit testing. */ public static synchronized void reset() { configuration = loadConfiguration(); notifyListeners(); }
/** * Prevent instantiation of UIManager. */ private UIManager() { // Listen for configuration changes Config.addPropertyChangeListener(this); }
originalConfig = Config.getInstance(); Configuration config = Config.copyConfiguration(originalConfig); config.setProperty(ConfigurationProperties.RESPONSE_CACHE_SETTINGS, override); Config.setConfiguration(config); Config.setConfiguration(originalConfig);
@Test public void testInterceptorDisabled() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "false"); Config.notifyListeners(); // No debug info should be rendered String xml = doRequest(); assertXpathEvaluatesTo("0", "count(//ui:debug/ui:debugInfo)", xml); }
@BeforeClass public static void setUp() { originalConfig = Config.getInstance(); CompositeConfiguration config = new CompositeConfiguration(originalConfig); MapConfiguration overrides = new MapConfiguration(new HashMap<String, Object>()); overrides.setProperty(ConfigurationProperties.INTEGRITY_ERROR_MODE, "true"); config.addConfiguration(overrides); Config.setConfiguration(config); }
@Test public void testFormatInternalMessage() { // With resource bundle set but no locale-specific text, should drop back to text in messages.properties. String result = I18nUtilities.format(PROVIDED_LOCALE, ConfigurationProperties.INTERNAL_MESSAGE_PREFIX + "printButton"); Assert.assertEquals("Incorrect text", "Print", result); // Without resource bundle set, should still drop back to text in messages.properties try { Configuration config = Config.getInstance(); config.clearProperty(ConfigurationProperties.I18N_RESOURCE_BUNDLE_BASE_NAME); result = I18nUtilities.format(PROVIDED_LOCALE, ConfigurationProperties.INTERNAL_MESSAGE_PREFIX + "printButton"); Assert.assertEquals("Incorrect text", "Print", result); } finally { Config.reset(); } } }
/** * When these tests are done put things back as they were. */ @After public void tearDownClass() { Config.reset(); }
@Test public void testErrorRedirect() { // Default for redirect should be false Assert.assertFalse("Redirect flag should be false", StepCountUtil.isErrorRedirect()); // Set redirect flag Configuration config = Config.copyConfiguration(originalConfig); config.addProperty(ConfigurationProperties.STEP_ERROR_URL, "test.url"); Config.setConfiguration(config); Assert.assertTrue("Redirect flag should be true", StepCountUtil.isErrorRedirect()); }
/** * <p> * Sets the current configuration.</p> * <p> * <b>Warning: </b> this will ignore any defined ConfigurationLoaders</p> * * @param configuration the configuration to set. */ public static synchronized void setConfiguration(final Configuration configuration) { Config.configuration = configuration; notifyListeners(); }
@AfterClass public static void tearDown() { // Remove overrides Config.setConfiguration(originalConfig); }
originalConfig = Config.getInstance(); Configuration config = Config.copyConfiguration(originalConfig); config.setProperty(ConfigurationProperties.RESPONSE_CACHE_SETTINGS, override); Config.setConfiguration(config); Config.setConfiguration(originalConfig);
@Test public void testInterceptorDisabled() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "false"); Config.notifyListeners(); MyApp app = new MyApp(); app.setLocked(true); // No debug info should be rendered String xml = doAjaxRequest(app); assertXpathEvaluatesTo("0", "count(//ui:debug)", xml); }
@BeforeClass public static void setUp() { originalConfig = Config.getInstance(); CompositeConfiguration config = new CompositeConfiguration(originalConfig); MapConfiguration overrides = new MapConfiguration(new HashMap<String, Object>()); overrides.setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "true"); overrides.setProperty(ConfigurationProperties.DEVELOPER_VALIDATE_XML, "true"); config.addConfiguration(overrides); Config.setConfiguration(config); }
/** * When these tests are done put things back as they were. */ @After public void tearDownClass() { Config.reset(); }
@Test public void testErrorUrl() { String testUrl = "test"; Configuration config = Config.copyConfiguration(originalConfig); // Clear current property (if exists) config.clearProperty(ConfigurationProperties.STEP_ERROR_URL); // Set redirect url config.addProperty(ConfigurationProperties.STEP_ERROR_URL, testUrl); Config.setConfiguration(config); Assert.assertEquals("Incorrect error url returned", testUrl, StepCountUtil.getErrorUrl()); }
/** * {@inheritDoc} */ public void refresh() { synchronized (lockObject) { // Now reset this object back to its initial state. initialiseInstanceVariables(); // Load all the parameters from scratch. load(); // Finally, notify all the listeners that have registered with this object that a change in properties has // occurred. Config.notifyListeners(); } }
@After public void tearDown() { // Remove overrides Config.setConfiguration(originalConfig); }
/** * {@inheritDoc} */ @Override public String getAppPreferenceParameter(final String key) { return Config.getInstance().getString(key); }
originalConfig = Config.getInstance(); Configuration config = Config.copyConfiguration(originalConfig); config.setProperty(ConfigurationProperties.RESPONSE_NO_CACHE_SETTINGS, override); Config.setConfiguration(config); Config.setConfiguration(originalConfig);