Search in sources :

Example 1 with TestBean2

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

the class VisitorFieldValidatorModelTest method testModelFieldErrorsAddedWithoutFieldPrefixForInterface.

public void testModelFieldErrorsAddedWithoutFieldPrefixForInterface() throws Exception {
    TestBean origBean = action.getBean();
    TestBean2 bean = new TestBean2();
    bean.setBirth(origBean.getBirth());
    bean.setCount(origBean.getCount());
    action.setBean(bean);
    assertTrue(action.getBean() instanceof TestBean2);
    container.getInstance(ActionValidatorManager.class).validate(action, null);
    assertTrue(action.hasFieldErrors());
    Map<String, List<String>> fieldErrors = action.getFieldErrors();
    // the required string validation inherited from the VisitorValidatorTestAction
    assertTrue(fieldErrors.containsKey("context"));
    // the bean validation which is now at the top level because we set the appendPrefix to false
    assertTrue(fieldErrors.containsKey("name"));
    List<String> nameMessages = fieldErrors.get("name");
    assertEquals(1, nameMessages.size());
    String nameMessage = nameMessages.get(0);
    assertEquals("You must enter a name.", nameMessage);
    // should also have picked up validation check for DataAware interface
    assertTrue(fieldErrors.containsKey("data"));
    List<String> dataMessages = fieldErrors.get("data");
    assertEquals(1, dataMessages.size());
    String dataMessage = dataMessages.get(0);
    assertEquals("You must enter a value for data.", dataMessage);
}
Also used : TestBean2(com.opensymphony.xwork2.test.TestBean2)

Example 2 with TestBean2

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

the class StrutsLocalizedTextProviderTest method testFindTextInChildProperty.

public void testFindTextInChildProperty() throws Exception {
    ModelDriven action = new ModelDrivenAction2();
    TestBean2 bean = (TestBean2) action.getModel();
    Bar bar = new Bar();
    bean.setBarObj(bar);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("hashCode", 0);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    ActionContext.getContext().getValueStack().push(action);
    ActionContext.getContext().getValueStack().push(action.getModel());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "invalid.fieldvalue.barObj.title", Locale.getDefault());
    assertEquals("Title is invalid!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Example 3 with TestBean2

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

the class StrutsLocalizedTextProviderTest method testActionGetText.

public void testActionGetText() throws Exception {
    ModelDrivenAction2 action = new ModelDrivenAction2();
    container.inject(action);
    TestBean2 bean = (TestBean2) action.getModel();
    Bar bar = new Bar();
    bean.setBarObj(bar);
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    ActionContext.getContext().getValueStack().push(action);
    ActionContext.getContext().getValueStack().push(action.getModel());
    String message = action.getText("barObj.title");
    assertEquals("Title:", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) TestBean2(com.opensymphony.xwork2.test.TestBean2) Mock(com.mockobjects.dynamic.Mock)

Example 4 with TestBean2

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

the class OgnlValueStackTest method testFindValueWithConversion.

public void testFindValueWithConversion() {
    // register converter
    TestBean2 tb2 = new TestBean2();
    OgnlValueStack stack = createValueStack();
    stack.push(tb2);
    Map myContext = stack.getContext();
    Map props = new HashMap();
    props.put("cat", "Kitty");
    ognlUtil.setProperties(props, tb2, myContext);
    // expect String to be converted into a Cat
    assertEquals("Kitty", tb2.getCat().getName());
    // findValue should be able to access the name
    Object value = stack.findValue("cat.name == 'Kitty'", Boolean.class);
    assertNotNull(value);
    assertEquals(Boolean.class, value.getClass());
    assertEquals(Boolean.TRUE, value);
    value = stack.findValue("cat == null", Boolean.class);
    assertNotNull(value);
    assertEquals(Boolean.class, value.getClass());
    assertEquals(Boolean.FALSE, value);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TestBean2(com.opensymphony.xwork2.test.TestBean2) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

TestBean2 (com.opensymphony.xwork2.test.TestBean2)4 Mock (com.mockobjects.dynamic.Mock)2 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)2 ModelDriven (com.opensymphony.xwork2.ModelDriven)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1