Search in sources :

Example 1 with ModelDrivenAction2

use of com.opensymphony.xwork2.test.ModelDrivenAction2 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 2 with ModelDrivenAction2

use of com.opensymphony.xwork2.test.ModelDrivenAction2 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 3 with ModelDrivenAction2

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

the class StrutsLocalizedTextProviderTest method testFindTextInInterface.

public void testFindTextInInterface() throws Exception {
    Action action = new ModelDrivenAction2();
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "test.foo", Locale.getDefault());
    assertEquals("Foo!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) SimpleAction(com.opensymphony.xwork2.SimpleAction) Action(com.opensymphony.xwork2.Action) Mock(com.mockobjects.dynamic.Mock)

Example 4 with ModelDrivenAction2

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

the class StrutsLocalizedTextProviderTest method testFindTextInPackage.

public void testFindTextInPackage() throws Exception {
    ModelDriven action = new ModelDrivenAction2();
    Mock mockActionInvocation = new Mock(ActionInvocation.class);
    mockActionInvocation.expectAndReturn("getAction", action);
    ActionContext.getContext().withActionInvocation((ActionInvocation) mockActionInvocation.proxy());
    String message = localizedTextProvider.findText(ModelDrivenAction2.class, "package.properties", Locale.getDefault());
    assertEquals("It works!", message);
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) ModelDriven(com.opensymphony.xwork2.ModelDriven) Mock(com.mockobjects.dynamic.Mock)

Example 5 with ModelDrivenAction2

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

the class ListAction method testFindConversionMappingForInterface.

public void testFindConversionMappingForInterface() {
    ModelDrivenAction2 action = new ModelDrivenAction2();
    stack.push(action);
    stack.push(action.getModel());
    Map<String, Object> ognlStackContext = stack.getContext();
    ognlStackContext.put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    String value = "asdf:123";
    Object o = converter.convertValue(ognlStackContext, action.getModel(), null, "barObj", value, Bar.class);
    assertNotNull(o);
    assertTrue(o instanceof Bar);
    Bar b = (Bar) o;
    assertEquals(value, b.getTitle() + ":" + b.getSomethingElse());
}
Also used : ModelDrivenAction2(com.opensymphony.xwork2.test.ModelDrivenAction2) Bar(com.opensymphony.xwork2.util.Bar)

Aggregations

ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)5 Mock (com.mockobjects.dynamic.Mock)4 ModelDriven (com.opensymphony.xwork2.ModelDriven)2 TestBean2 (com.opensymphony.xwork2.test.TestBean2)2 Action (com.opensymphony.xwork2.Action)1 SimpleAction (com.opensymphony.xwork2.SimpleAction)1 Bar (com.opensymphony.xwork2.util.Bar)1