/** * {@inheritDoc} */ @Override public String getRequestValue(final Request request) { if (isPresent(request)) { String value = request.getParameter(getId()); // An empty string is treated as null return (Util.empty(value)) ? null : value; } else { return getValue(); } }
@Test public void testInterceptor() throws XpathException, SAXException, IOException { Config.getInstance().setProperty(ConfigurationProperties.DEVELOPER_DEBUG_ENABLED, "true"); Config.notifyListeners(); MyApp app = new MyApp(); app.setLocked(true); // Only the label should have debug info rendered String xml = doAjaxRequest(app); assertXpathEvaluatesTo("1", "count(//ui:debug/ui:debugInfo)", xml); assertXpathEvaluatesTo(app.target.getId(), "//ui:debug/ui:debugInfo/@for", xml); assertXpathEvaluatesTo(app.target.getClass().getName(), "//ui:debug/ui:debugInfo/@class", xml); assertXpathEvaluatesTo(app.target.getClass().getName(), "//ui:debug/ui:debugInfo/@type", xml); assertXpathEvaluatesTo("true", "//ui:debug/ui:debugInfo/ui:debugDetail[@key='defaultState']/@value", xml); }
setActiveContext(lastRowContext); textField.setText(text2); String lastRowId = textField.getId(); Assert.assertEquals("Last row should have user text", text2, textField.getText()); Assert.assertTrue("Row 1 id should not have changed", lastRowId.equals(textField.getId())); setActiveContext(repeater.getRowContexts().get(1)); Assert.assertEquals("Row 2 should have bean text", ROW_DATA[0], textField.getText());
@Test public void testRequest() { // Create a test wcomponent with a label and an entry field. WTextField name = new WTextField(); WLabel label = new WLabel("Hero", name); WPanel panel = new WPanel(); panel.add(label); panel.add(name); // Create a mock context and request. setActiveContext(createUIContext()); MockRequest request = new MockRequest(); // Check that the text field successfully stores text. name.setText("Batman"); Assert.assertEquals("text accessors incorrect", "Batman", name.getText()); // Service a request that simulates a user entering a value // into the entry field. request.setParameter(name.getId(), "Superman"); panel.serviceRequest(request); Assert.assertEquals("text incorrect after request", "Superman", name.getText()); // Render the output and log it. String output = WebUtilities.render(request, panel); LOG.debug(output); } }
request.setParameter(testApp.getSearchCriteriaPage().getDataField().getId(), "Joe Bloggs"); request.setParameter(testApp.getSearchCriteriaPage().getNumRows().getId(), "200"); request.setParameter(testApp.getSearchCriteriaPage().getRowsPerPage().getId(), "20");
@Test public void testConstructor() { WTextField component = new WTextField(); WFieldErrorIndicator indicator = new WFieldErrorIndicator(component); Assert.assertEquals("Incorrect indicator type", AbstractWFieldIndicator.FieldIndicatorType.ERROR, indicator .getFieldIndicatorType()); Assert.assertEquals("Incorrect releated field", component, indicator.getTargetComponent()); Assert.assertEquals("Incorrect releated field id", component.getId(), indicator. getRelatedFieldId()); }
@Test public void testConstructor() { WTextField component = new WTextField(); WFieldWarningIndicator indicator = new WFieldWarningIndicator(component); Assert.assertEquals("Incorrect indicator type", AbstractWFieldIndicator.FieldIndicatorType.WARN, indicator.getFieldIndicatorType()); Assert.assertEquals("Incorrect releated field", component, indicator.getTargetComponent()); Assert.assertEquals("Incorrect related field id", component.getId(), indicator.getRelatedFieldId()); } }
@Test public void testGetRequestValue() { WTextField field = new WTextField(); field.setLocked(true); setActiveContext(createUIContext()); // Set current value field.setText("A"); // Empty Request (not present, should return current value) MockRequest request = new MockRequest(); Assert. assertEquals( "Current value of the field should have been returned for empty request", "A", field.getRequestValue(request)); // Request with "empty" value (should return null as an empty value on the request is treated as null) request = new MockRequest(); request.setParameter(field.getId(), ""); Assert .assertNull("Null should have been returned for request with empty value", field. getRequestValue(request)); // Request with value (should return the value on the request) request = new MockRequest(); request.setParameter(field.getId(), "X"); Assert.assertEquals("Value from the request should have been returned", "X", field. getRequestValue(request)); }
request.setParameter(field.getId(), ""); boolean changed = field.doHandleRequest(request); request.setParameter(field.getId(), ""); changed = field.doHandleRequest(request); request.setParameter(field.getId(), "X"); changed = field.doHandleRequest(request); request.setParameter(field.getId(), "X"); changed = field.doHandleRequest(request); request.setParameter(field.getId(), ""); changed = field.doHandleRequest(request);
@Test public void testRenderedFormatWithFocussedComponent() throws XpathException, IOException, SAXException { MockWEnvironment environment = new MockWEnvironment(); WApplication application = new WApplication(); environment.setPostPath("WApplicationRendererTest.postPath"); WTextField focussedComponent = new WTextField(); application.add(focussedComponent); UIContext uic = createUIContext(); uic.setEnvironment(environment); uic.setUI(application); uic.setFocusRequired(true); uic.setFocussed(focussedComponent); setActiveContext(uic); assertSchemaMatch(application); assertXpathEvaluatesTo(environment.getPostPath(), "//ui:application/@applicationUrl", application); assertXpathEvaluatesTo(WComponent.DEFAULT_APPLICATION_ID, "//ui:application/@id", application); assertXpathEvaluatesTo(environment.getWServletPath(), "//ui:application/@ajaxUrl", application); assertXpathEvaluatesTo(focussedComponent.getId(), "//ui:application/@defaultFocusId", application); uic.setFocusRequired(false); assertXpathNotExists("//ui:application/@defaultFocusId", application); }
AjaxHelper.registerComponent(app.target.getId(), app.trigger.getId()); request.setParameter(WServlet.AJAX_TRIGGER_PARAM_NAME, app.trigger.getId()); request.setParameter(Environment.STEP_VARIABLE, String.valueOf(clientStep));
AjaxHelper.registerComponent(app.target.getId(), app.trigger.getId()); request.setParameter(WServlet.AJAX_TRIGGER_PARAM_NAME, app.trigger.getId());
assertXpathEvaluatesTo(textField.getId(), "//ui:textfield/@id", textField); assertXpathNotExists("//ui:textfield/@disabled", textField); assertXpathNotExists("//ui:textfield/@hidden", textField);