use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class UIContextImpl_Test method testFocusableInWRepeaterNested.
@Test
public void testFocusableInWRepeaterNested() {
// Beans list
final String optionX = "X";
final String optionY = "Y";
final List<String> beans = Arrays.asList(new String[] { optionX, optionY });
// Another beans list for nested repeater
final String optionA = "A";
final String optionB = "B";
final String optionC = "C";
final List<String> beans2 = Arrays.asList(new String[] { optionA, optionB, optionC });
// Setup the nested repeater
WRepeater repeater2 = new WRepeater();
WComponent content2 = new WBeanComponent() {
@Override
public void handleRequest(final Request request) {
super.handleRequest(request);
UIContext uic = UIContextHolder.getCurrent();
if (uic instanceof SubUIContext) {
SubUIContext suic = (SubUIContext) uic;
// Set the component on the third row to have focus
if (suic.getRowIndex() == 2) {
uic.setFocussed(this, uic);
}
}
}
};
repeater2.setRepeatedComponent(content2);
// Setup the top level repeater
WRepeater repeater = new WRepeater();
WContainer content = new WContainer() {
@Override
public void handleRequest(final Request request) {
super.handleRequest(request);
UIContext uic = UIContextHolder.getCurrent();
if (uic instanceof SubUIContext) {
SubUIContext suic = (SubUIContext) uic;
if (suic.getRowIndex() == 0) {
// Set the bean list on the nested repeater, only for the first row
WRepeater nested = (WRepeater) getChildAt(0);
nested.setBeanList(beans2);
}
}
}
};
content.add(repeater2);
repeater.setRepeatedComponent(content);
// Set the repeater as the "UI" for context
UIContext uic = new UIContextImpl();
uic.setUI(repeater);
setActiveContext(uic);
// Setup the bean list on the top level repeater
repeater.setBeanList(beans);
// ServiceRequest on the repeater (to create the SubUiContexts)
MockRequest request = new MockRequest();
repeater.serviceRequest(request);
// Simulate clearing of scratch map
uic.clearScratchMap();
// Get the focused component
String focusId = uic.getFocussedId();
// Get the ID of the component on the second row
String rowComponentId = null;
try {
UIContext suic = repeater.getRowContext(optionX);
UIContextHolder.pushContext(suic);
UIContext suic2 = repeater2.getRowContext(optionC);
UIContextHolder.pushContext(suic2);
rowComponentId = content2.getId();
} finally {
UIContextHolder.reset();
}
Assert.assertNotNull("Focus ID should not be null", focusId);
Assert.assertEquals("Focus ID should be the ID for the component on the 2nd row", rowComponentId, focusId);
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WButton_Test method getButtonText.
/**
* Returns the text for a button created with the given data.
*
* @param useSharedText true if the button should have shared text
* @param useUserText true if the button should have user text
* @param useSharedValue true if the button should have a shared value
* @param useUserValue true if the button should have a user value
* @param useBeanValue true if the button should have a bean provider
* @param nullBean true if the provided bean should be null
*
* @return the button text that will be displayed to the user.
*/
private String getButtonText(final boolean useSharedText, final boolean useUserText, final boolean useSharedValue, final boolean useUserValue, final boolean useBeanValue, final boolean nullBean) {
WButton button = createButton(useSharedText, useUserText, useSharedValue, useUserValue, useBeanValue, nullBean);
setActiveContext(createUIContext());
try {
button.preparePaintComponent(new MockRequest());
return button.getText();
} finally {
UIContextHolder.reset();
}
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WButton_Test method getButtonValue.
/**
* Returns the value for a button created with the given data.
*
* @param useSharedText true if the button should have shared text
* @param useUserText true if the button should have user text
* @param useSharedValue true if the button should have a shared value
* @param useUserValue true if the button should have a user value
* @param useBeanValue true if the button should have a bean provider
* @param nullBean true if the provided bean should be null
*
* @return the button value will be used for a user.
*/
private String getButtonValue(final boolean useSharedText, final boolean useUserText, final boolean useSharedValue, final boolean useUserValue, final boolean useBeanValue, final boolean nullBean) {
WButton button = createButton(useSharedText, useUserText, useSharedValue, useUserValue, useBeanValue, nullBean);
setActiveContext(createUIContext());
try {
button.preparePaintComponent(new MockRequest());
return button.getValue();
} finally {
UIContextHolder.reset();
}
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WButton_Test method testSetPressed.
@Test
public void testSetPressed() {
WButton button = new WButton("Test");
button.setLocked(true);
setActiveContext(createUIContext());
button.setPressed(true, new MockRequest());
Assert.assertTrue("Button should be pressed", button.isPressed());
Assert.assertFalse("Button should not be in default state", button.isDefaultState());
button.setPressed(false, new MockRequest());
Assert.assertFalse("Button should be pressed", button.isPressed());
button.setDisabled(true);
button.setPressed(true, new MockRequest());
Assert.assertTrue("Button should be disabled", button.isDisabled());
Assert.assertFalse("Button should be pressed when disabled", button.isPressed());
}
use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.
the class WButton_Test method testActionSetPressed.
@Test
public void testActionSetPressed() {
WButton button = new WButton("Test");
button.setLocked(true);
UIContext uic = createUIContext();
setActiveContext(uic);
uic.setUI(button);
TestAction testAction = new TestAction();
testAction.reset();
button.setAction(testAction);
button.setPressed(true, new MockRequest());
Assert.assertEquals("Button was not pressed", true, button.isPressed());
}
Aggregations