/** * Shorthand convenience method to get the Configuration instance. * * @return the Configuration instance. */ private static Configuration get() { return Config.getInstance(); }
/** * {@inheritDoc} */ @Override public String getAppPreferenceParameter(final String key) { return Config.getInstance().getString(key); }
@Before public void setUp() { originalConfig = Config.getInstance(); }
@BeforeClass public static void setUp() { Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, ""); Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_MODE_CLUSTER_EMULATION, "true"); Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_MODE_ERROR_HANDLING, true); Config.getInstance().setProperty("bordertech.wcomponents.factory.impl.com.github.bordertech.wcomponents.FatalErrorPageFactory", "com.github.bordertech.wcomponents.container.AbstractContainerHelper_Test$MyFatalErrorPageFactory"); Config.getInstance().setProperty("bordertech.wcomponents.factory.impl.com.github.bordertech.wcomponents.container.PageShell", "com.github.bordertech.wcomponents.container.AbstractContainerHelper_Test$MyCustomPageShell"); TransformXMLTestHelper.reloadTransformer(); }
@Test public void testNewInstanceWithImpl() { Config.getInstance().setProperty(ConfigurationProperties.FACTORY_PREFIX + TestInterface.class.getName(), TestInterfaceImpl.class.getName()); Assert.assertTrue("Should be an instanceof TestInterface", Factory.newInstance( TestInterface.class) instanceof TestInterface); }
@Test public void testImplementationExists() { Assert.assertFalse("No implementation should exist", Factory.implementationExists( TestInterface.class)); final String key = ConfigurationProperties.FACTORY_PREFIX + TestInterface.class.getName(); Config.getInstance().setProperty(key, " "); Assert.assertFalse("No implementation should exist", Factory.implementationExists( TestInterface.class)); Config.getInstance().setProperty(key, TestInterfaceImpl.class.getName()); Assert.assertTrue("An implementation should exist", Factory.implementationExists( TestInterface.class)); }
/** * Ensure that the interceptor does nothing when the user agent string opts out. */ @Test public void testPaintWithUserAgentOverride() { MyComponent testUI = new MyComponent(TransformXMLTestHelper.TEST_XML); Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, ""); TransformXMLTestHelper.reloadTransformer(); Map<String, String> headers = new HashMap<String, String>(); headers.put("User-Agent", "Mozilla/5.0 Firefox/26.0 wcnoxslt"); TestResult actual = generateOutput(testUI, headers); Assert.assertEquals("XML should not be transformed when useragent string flag present", TransformXMLTestHelper.TEST_XML, actual.result); }
/** * Ensure that the interceptor honors the "on" property. */ @Test public void testPaintWhileEnabled() { MyComponent testUI = new MyComponent(TEST_HTML); Config.getInstance().setProperty(ConfigurationProperties.I18N_THEME_RESOURCE_BUNDLE_BASE_NAME, "i18n/theme"); TestResult actual = generateOutput(testUI); Assert.assertEquals("Template should not be rendered when interceptor disabled", EXPECTED_RENDERED, actual.result); }
/** * Test that the interceptor transforms our XML when it is enabled. */ @Test public void testPaintWhileEnabled() { MyComponent testUI = new MyComponent(TransformXMLTestHelper.TEST_XML); Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, ""); TransformXMLTestHelper.reloadTransformer(); TestResult actual = generateOutput(testUI); Assert.assertEquals("XML should be transformed when interceptor enabled", TransformXMLTestHelper.EXPECTED, actual.result); Assert.assertEquals("The content type should be correctly set", WebUtilities.CONTENT_TYPE_HTML, actual.contentType); }
@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); }
/** * Ensure that the interceptor does nothing as long as the controlling property is disabled. */ @Test public void testPaintWhileEnabledWithThemeContentPathSet() { MyComponent testUI = new MyComponent(TransformXMLTestHelper.TEST_XML); Config.getInstance().setProperty(ConfigurationProperties.THEME_CONTENT_PATH, "set"); TransformXMLTestHelper.reloadTransformer(); TestResult actual = generateOutput(testUI); Assert.assertEquals("XML should be transformed when interceptor enabled and theme content path set", TransformXMLTestHelper.EXPECTED, actual.result); }
@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); }
@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); }
@Test public void testInterceptor() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "true"); Config.notifyListeners(); // Only the label should have debug info rendered String xml = doRequest(); assertXpathEvaluatesTo("1", "count(//ui:debug/ui:debugInfo)", xml); assertXpathEvaluatesTo(new WApplication().getId(), "//ui:debugInfo/@for", xml); assertXpathEvaluatesTo(WApplication.class.getName(), "//ui:debug/ui:debugInfo/@class", xml); assertXpathEvaluatesTo(WApplication.class.getName(), "//ui:debug/ui:debugInfo/@type", xml); assertXpathEvaluatesTo("false", "//ui:debug/ui:debugInfo/ui:debugDetail[@key='defaultState']/@value", xml); }
@Test public void testErrorDirectContent() { Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, "http://test.test"); MyApp app = new MyApp(); app.setLocked(true); MockResponse response = sendContentRequest(app.appContent, 1, 99); Assert.assertEquals("Should have returned error", HttpServletResponse.SC_BAD_REQUEST, response.getErrorCode()); }
@Test public void testSubSessionsEnabledNoSSID() throws ServletException, IOException { Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "true"); MyWServlet servlet = new MyWServlet(new WText("test")); servlet.init(new MockServletConfig()); MockHttpSession session = new MockHttpSession(); servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse()); Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount); // No SSID should trigger a new subsession servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse()); Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount); }
@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); }
@Test public void testInterceptorRedirect() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, "http://test.test"); MyApp app = new MyApp(); app.setLocked(true); MockResponse response = doAjaxRequest(app, 1, 99); assertXpathEvaluatesTo("http://test.test", "//ui:redirect/@url", response.getWriterOutput()); }
@Test public void testInterceptorWarp() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.STEP_ERROR_URL, ""); MyApp app = new MyApp(); app.setLocked(true); // Should redirect to app postpath MockResponse response = doAjaxRequest(app, 1, 99); assertXpathEvaluatesTo(APP_POSTPATH, "//ui:redirect/@url", response.getWriterOutput()); }
@Test public void testSubSessionsDisabledNoSSID() throws ServletException, IOException { Config.getInstance().setProperty(ConfigurationProperties.SERVLET_ENABLE_SUBSESSIONS, "false"); MyWServlet servlet = new MyWServlet(new WText("test")); servlet.init(new MockServletConfig()); MockHttpSession session = new MockHttpSession(); servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse()); Assert.assertEquals("Incorrect invocation count", 1, servlet.lastInvocationCount); servlet.service(new MockHttpServletRequest(session), new MockHttpServletResponse()); Assert.assertEquals("Incorrect invocation count", 2, servlet.lastInvocationCount); }