Search in sources :

Example 1 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class SessionTokenInterceptor_Test method setUp.

@Before
public void setUp() {
    component = new MyBackingComponent();
    interceptor = new SessionTokenInterceptor();
    interceptor.setBackingComponent(component);
    uic = new UIContextImpl();
    uic.setUI(component);
    uic.setEnvironment(new MockWEnvironment());
    setActiveContext(uic);
    request = new MockRequest();
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Before(org.junit.Before)

Example 2 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class TargetableInterceptor_Test method testServiceRequestWithUndefinedTarget.

@Test(expected = SystemException.class)
public void testServiceRequestWithUndefinedTarget() {
    // UI should change when a target is present in a request
    MockRequest request = new MockRequest();
    request.setParameter(Environment.TARGET_ID, "TargetableInterceptor_Test.testServiceRequestWithUndefinedTarget");
    interceptor.serviceRequest(request);
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 3 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WrongStepServerInterceptor_Test method setUp.

@Before
public void setUp() {
    component = new MyBackingComponent();
    interceptor = new WrongStepServerInterceptor();
    interceptor.setBackingComponent(component);
    uic = new UIContextImpl();
    uic.setUI(component);
    uic.setEnvironment(new MockWEnvironment());
    setActiveContext(uic);
    request = new MockRequest();
    // Default to GET method
    request.setMethod("GET");
    originalConfig = Config.getInstance();
}
Also used : MockWEnvironment(com.github.bordertech.wcomponents.MockWEnvironment) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Before(org.junit.Before)

Example 4 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WMultiTextField_Test method testGetRequestValue.

@Test
public void testGetRequestValue() {
    WMultiTextField field = new WMultiTextField();
    setActiveContext(createUIContext());
    field.setTextInputs(ENTERED_1);
    // Empty Request - return current value
    MockRequest request = new MockRequest();
    Assert.assertTrue("Request value should be the current value for an empty request", Arrays.equals(ENTERED_1, field.getRequestValue(request)));
    // Empty values on the request
    String[] value = new String[] { "", null };
    request = new MockRequest();
    request.setParameter(field.getId(), value);
    Assert.assertNull("Request value should be null for empty values on request", field.getRequestValue(request));
    // Values on the request
    request = new MockRequest();
    request.setParameter(field.getId(), ENTERED_1_2);
    Assert.assertTrue("Request value should be the values on the request", Arrays.equals(ENTERED_1_2, field.getRequestValue(request)));
    // An empty string or null in the array should be removed
    String[] inputs2 = new String[] { "", "x", "y", "", "", null, "z" };
    request.setParameter(field.getId(), inputs2);
    Assert.assertTrue("Request value should be the values on the request without the null and empty entries", Arrays.equals(new String[] { "x", "y", "z" }, field.getRequestValue(request)));
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 5 with MockRequest

use of com.github.bordertech.wcomponents.util.mock.MockRequest in project wcomponents by BorderTech.

the class WNumberField_Test method processDoHandleRequestWithEmptyRequest.

/**
 * @return a numberField processed with a request with an empty value
 */
private WNumberField processDoHandleRequestWithEmptyRequest() {
    resetContext();
    WNumberField numberField = new WNumberField();
    String numberFieldId = numberField.getId();
    numberField.setLocked(true);
    // Empty Request
    setActiveContext(createUIContext());
    MockRequest request = new MockRequest();
    request.setParameter(numberFieldId, "");
    numberField.doHandleRequest(request);
    return numberField;
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

Aggregations

MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)250 Test (org.junit.Test)216 UIContext (com.github.bordertech.wcomponents.UIContext)22 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)16 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)13 PrintWriter (java.io.PrintWriter)13 Request (com.github.bordertech.wcomponents.Request)12 ArrayList (java.util.ArrayList)10 Date (java.util.Date)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 StringWriter (java.io.StringWriter)7 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 SubUIContext (com.github.bordertech.wcomponents.WRepeater.SubUIContext)6 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 BigDecimal (java.math.BigDecimal)5 Escape (com.github.bordertech.wcomponents.Escape)4 WTextField (com.github.bordertech.wcomponents.WTextField)4 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3