Search in sources :

Example 1 with Equidae

use of com.opensymphony.xwork2.test.Equidae in project struts by apache.

the class ScopedModelDrivenInterceptorTest method testScopedModelDrivenActionWithSetClassName.

public void testScopedModelDrivenActionWithSetClassName() throws Exception {
    inter.setScope("request");
    inter.setClassName("com.opensymphony.xwork2.test.Equidae");
    inter.setName("queen");
    ScopedModelDriven action = new MyEquidaeScopedModelDrivenAction();
    MockActionInvocation mai = new MockActionInvocation();
    MockActionProxy map = new MockActionProxy();
    ActionConfig ac = new ActionConfig.Builder("", "", "").build();
    map.setConfig(ac);
    mai.setAction(action);
    mai.setProxy(map);
    inter.intercept(mai);
    inter.destroy();
    assertNotNull(action.getModel());
    assertNotNull(action.getScopeKey());
    assertEquals("queen", action.getScopeKey());
    Object model = ActionContext.getContext().get(action.getScopeKey());
    assertNotNull(model);
    assertTrue("Model should be an Equidae object", model instanceof Equidae);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) MockActionInvocation(com.opensymphony.xwork2.mock.MockActionInvocation) Equidae(com.opensymphony.xwork2.test.Equidae) MockActionProxy(com.opensymphony.xwork2.mock.MockActionProxy)

Example 2 with Equidae

use of com.opensymphony.xwork2.test.Equidae in project struts by apache.

the class StringValidatorTest method testRequiredStringWithNullValue.

public void testRequiredStringWithNullValue() throws Exception {
    Equidae equidae = new Equidae();
    equidae.setHorse(null);
    DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) Equidae(com.opensymphony.xwork2.test.Equidae)

Example 3 with Equidae

use of com.opensymphony.xwork2.test.Equidae in project struts by apache.

the class StringValidatorTest method testStringLength.

public void testStringLength() throws Exception {
    Equidae equidae = new Equidae();
    equidae.setCow("asdf");
    equidae.setDonkey("asdf");
    ActionContext.getContext().getValueStack().push(equidae);
    DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    Map fieldErrors = context.getFieldErrors();
    // cow
    assertTrue(fieldErrors.containsKey("cow"));
    List errors = (List) fieldErrors.get("cow");
    assertEquals(2, errors.size());
    assertEquals("noTrim-min5", errors.get(0));
    assertEquals("noTrim-min5-max10", errors.get(1));
    // donkey
    assertTrue(fieldErrors.containsKey("donkey"));
    errors = (List) fieldErrors.get("donkey");
    assertEquals(2, errors.size());
    assertEquals("trim-min5", errors.get(0));
    assertEquals("trim-min5-max10", errors.get(1));
    equidae.setCow("asdf  ");
    equidae.setDonkey("asdf  ");
    ActionContext.getContext().getValueStack().push(equidae);
    context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    fieldErrors = context.getFieldErrors();
    // cow
    assertFalse(fieldErrors.containsKey("cow"));
    // donkey
    assertTrue(fieldErrors.containsKey("donkey"));
    errors = (List) fieldErrors.get("donkey");
    assertEquals(2, errors.size());
    assertEquals("trim-min5", errors.get(0));
    assertEquals("trim-min5-max10", errors.get(1));
    equidae.setCow("asdfasdf");
    equidae.setDonkey("asdfasdf");
    ActionContext.getContext().getValueStack().push(equidae);
    context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    fieldErrors = context.getFieldErrors();
    // cow
    assertFalse(fieldErrors.containsKey("cow"));
    // donkey
    assertFalse(fieldErrors.containsKey("donkey"));
    equidae.setCow("asdfasdf   ");
    equidae.setDonkey("asdfasdf   ");
    ActionContext.getContext().getValueStack().push(equidae);
    context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    fieldErrors = context.getFieldErrors();
    // cow
    assertTrue(fieldErrors.containsKey("cow"));
    errors = (List) fieldErrors.get("cow");
    assertEquals(2, errors.size());
    assertEquals("noTrim-min5-max10", errors.get(0));
    assertEquals("noTrim-max10", errors.get(1));
    // donkey
    assertFalse(fieldErrors.containsKey("donkey"));
    equidae.setCow("asdfasdfasdf");
    equidae.setDonkey("asdfasdfasdf");
    ActionContext.getContext().getValueStack().push(equidae);
    context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    fieldErrors = context.getFieldErrors();
    // cow
    assertTrue(fieldErrors.containsKey("cow"));
    errors = (List) fieldErrors.get("cow");
    assertEquals(2, errors.size());
    assertEquals("noTrim-min5-max10", errors.get(0));
    assertEquals("noTrim-max10", errors.get(1));
    // donkey
    assertTrue(fieldErrors.containsKey("donkey"));
    errors = (List) fieldErrors.get("donkey");
    assertEquals(2, errors.size());
    assertEquals("trim-min5-max10", errors.get(0));
    assertEquals("trim-max10", errors.get(1));
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) List(java.util.List) Equidae(com.opensymphony.xwork2.test.Equidae) Map(java.util.Map)

Example 4 with Equidae

use of com.opensymphony.xwork2.test.Equidae in project struts by apache.

the class StringValidatorTest method testRequiredString.

public void testRequiredString() throws Exception {
    Equidae equidae = new Equidae();
    // everything should fail
    equidae.setHorse("");
    ActionContext.getContext().getValueStack().push(equidae);
    DelegatingValidatorContext context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    Map fieldErrors = context.getFieldErrors();
    assertTrue(fieldErrors.containsKey("horse"));
    assertEquals(2, ((List) fieldErrors.get("horse")).size());
    // trim = false should fail
    equidae.setHorse("  ");
    ActionContext.getContext().getValueStack().push(equidae);
    context = new DelegatingValidatorContext(new ValidationAwareSupport(), tpf);
    container.getInstance(ActionValidatorManager.class).validate(equidae, null, context);
    assertTrue(context.hasFieldErrors());
    fieldErrors = context.getFieldErrors();
    assertTrue(fieldErrors.containsKey("horse"));
    List errors = (List) fieldErrors.get("horse");
    assertEquals(1, errors.size());
    assertEquals("trim", (String) errors.get(0));
}
Also used : ValidationAwareSupport(com.opensymphony.xwork2.ValidationAwareSupport) List(java.util.List) Equidae(com.opensymphony.xwork2.test.Equidae) Map(java.util.Map)

Aggregations

Equidae (com.opensymphony.xwork2.test.Equidae)4 ValidationAwareSupport (com.opensymphony.xwork2.ValidationAwareSupport)3 List (java.util.List)2 Map (java.util.Map)2 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 MockActionInvocation (com.opensymphony.xwork2.mock.MockActionInvocation)1 MockActionProxy (com.opensymphony.xwork2.mock.MockActionProxy)1