Search in sources :

Example 61 with Bar

use of com.opensymphony.xwork2.util.Bar in project struts by apache.

the class XmlConfigurationProviderResultsTest method testActions.

public void testActions() throws ConfigurationException {
    final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-results.xml";
    ConfigurationProvider provider = buildConfigurationProvider(filename);
    HashMap<String, String> parameters = new HashMap<>();
    HashMap<String, ResultConfig> results = new HashMap<>();
    results.put("chainDefaultTypedResult", new ResultConfig.Builder("chainDefaultTypedResult", ActionChainResult.class.getName()).build());
    results.put("mockTypedResult", new ResultConfig.Builder("mockTypedResult", MockResult.class.getName()).build());
    Map<String, String> resultParams = new HashMap<>();
    resultParams.put("actionName", "bar.vm");
    results.put("specificLocationResult", new ResultConfig.Builder("specificLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
    resultParams = new HashMap<>();
    resultParams.put("actionName", "foo.vm");
    results.put("defaultLocationResult", new ResultConfig.Builder("defaultLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
    resultParams = new HashMap<>();
    resultParams.put("foo", "bar");
    results.put("noDefaultLocationResult", new ResultConfig.Builder("noDefaultLocationResult", ActionChainResult.class.getName()).addParams(resultParams).build());
    ActionConfig expectedAction = new ActionConfig.Builder("default", "Bar", SimpleAction.class.getName()).addParams(parameters).addResultConfigs(results).build();
    // execute the configuration
    provider.init(configuration);
    provider.loadPackages();
    PackageConfig pkg = configuration.getPackageConfig("default");
    Map<String, ActionConfig> actionConfigs = pkg.getActionConfigs();
    // assertions
    assertEquals(1, actionConfigs.size());
    ActionConfig action = actionConfigs.get("Bar");
    assertEquals(expectedAction, action);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) ResultConfig(com.opensymphony.xwork2.config.entities.ResultConfig) MockResult(com.opensymphony.xwork2.mock.MockResult) HashMap(java.util.HashMap) ActionChainResult(com.opensymphony.xwork2.ActionChainResult) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 62 with Bar

use of com.opensymphony.xwork2.util.Bar in project struts by apache.

the class AnnotationXWorkConverterTest method testValueStackWithTypeParameter.

public void testValueStackWithTypeParameter() {
    ValueStack stack = ActionContext.getContext().getValueStack();
    stack.push(new Foo1());
    Bar1 bar = (Bar1) stack.findValue("bar", Bar1.class);
    assertNotNull(bar);
}
Also used : ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 63 with Bar

use of com.opensymphony.xwork2.util.Bar in project struts by apache.

the class OgnlUtilTest method testDeepSetting.

public void testDeepSetting() {
    Foo foo = new Foo();
    foo.setBar(new Bar());
    Map<String, Object> context = ognlUtil.createDefaultContext(foo);
    Map<String, Object> props = new HashMap<>();
    props.put("bar.title", "i am barbaz");
    ognlUtil.setProperties(props, foo, context);
    assertEquals(foo.getBar().getTitle(), "i am barbaz");
}
Also used : Bar(com.opensymphony.xwork2.util.Bar) HashMap(java.util.HashMap) Foo(com.opensymphony.xwork2.util.Foo)

Example 64 with Bar

use of com.opensymphony.xwork2.util.Bar in project struts by apache.

the class SetPropertiesTest method testValueStackSetValueEmptyStringAsLong.

public void testValueStackSetValueEmptyStringAsLong() {
    Bar bar = new Bar();
    ValueStack vs = ActionContext.getContext().getValueStack();
    vs.getContext().put(XWorkConverter.REPORT_CONVERSION_ERRORS, Boolean.TRUE);
    vs.push(bar);
    vs.setValue("id", "");
    assertNull(bar.getId());
    assertEquals(0, bar.getFieldErrors().size());
    bar.setId(null);
    vs.setValue("id", new String[] { "" });
    assertNull(bar.getId());
    assertEquals(0, bar.getFieldErrors().size());
}
Also used : Bar(com.opensymphony.xwork2.util.Bar) ValueStack(com.opensymphony.xwork2.util.ValueStack)

Example 65 with Bar

use of com.opensymphony.xwork2.util.Bar in project struts by apache.

the class SetPropertiesTest method doTestAddingAndModifyingCollectionWithObjects.

public void doTestAddingAndModifyingCollectionWithObjects(Collection barColl) {
    ValueStack vs = ActionContext.getContext().getValueStack();
    Foo foo = new Foo();
    foo.setBarCollection(barColl);
    Bar bar1 = new Bar();
    bar1.setId(new Long(11));
    barColl.add(bar1);
    Bar bar2 = new Bar();
    bar2.setId(new Long(22));
    barColl.add(bar2);
    foo.setAnnotatedBarCollection(barColl);
    // try modifying bar1 and bar2
    // check the logs here to make sure
    // the Map is being created
    ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
    ReflectionContextState.setReportingConversionErrors(vs.getContext(), true);
    vs.push(foo);
    String bar1Title = "The Phantom Menace";
    String bar2Title = "The Clone Wars";
    vs.setValue("barCollection(22).title", bar2Title);
    vs.setValue("barCollection(11).title", bar1Title);
    for (Object aBarColl : barColl) {
        Bar next = (Bar) aBarColl;
        if (next.getId().intValue() == 22) {
            assertEquals(bar2Title, next.getTitle());
        } else {
            assertEquals(bar1Title, next.getTitle());
        }
    }
    Bar bar3 = new Bar();
    bar3.setId(new Long(33));
    barColl.add(bar3);
    Bar bar4 = new Bar();
    bar4.setId(new Long(44));
    barColl.add(bar4);
    String bar1TitleByAnnotation = "The Phantom Menace By Annotation";
    String bar2TitleByAnnotation = "The Clone Wars By Annotation";
    vs.setValue("annotatedBarCollection(44).title", bar2TitleByAnnotation);
    vs.setValue("annotatedBarCollection(33).title", bar1TitleByAnnotation);
    for (Object aBarColl : barColl) {
        Bar next = (Bar) aBarColl;
        if (next.getId().intValue() == 44) {
            assertEquals(bar2TitleByAnnotation, next.getTitle());
        } else if (next.getId().intValue() == 33) {
            assertEquals(bar1TitleByAnnotation, next.getTitle());
        }
    }
    // now test adding to a collection
    String bar3Title = "Revenge of the Sith";
    String bar4Title = "A New Hope";
    vs.setValue("barCollection.makeNew[4].title", bar4Title, true);
    vs.setValue("barCollection.makeNew[0].title", bar3Title, true);
    assertEquals(6, barColl.size());
    for (Object aBarColl : barColl) {
        Bar next = (Bar) aBarColl;
        if (next.getId() == null) {
            assertNotNull(next.getTitle());
            assertTrue(next.getTitle().equals(bar4Title) || next.getTitle().equals(bar3Title));
        }
    }
    // now test adding to a collection by annotation
    String bar3TitleByAnnotation = "Revenge of the Sith By Annotation";
    String bar4TitleByAnnotation = "A New Hope By Annotation";
    vs.setValue("annotatedBarCollection.makeNew[5].title", bar4TitleByAnnotation, true);
    vs.setValue("annotatedBarCollection.makeNew[1].title", bar3TitleByAnnotation, true);
    assertEquals(8, barColl.size());
    for (Object aBarColl : barColl) {
        Bar next = (Bar) aBarColl;
        if (next.getId() == null) {
            assertNotNull(next.getTitle());
            assertTrue(next.getTitle().equals(bar4TitleByAnnotation) || next.getTitle().equals(bar3TitleByAnnotation) || next.getTitle().equals(bar4Title) || next.getTitle().equals(bar3Title));
        }
    }
}
Also used : Bar(com.opensymphony.xwork2.util.Bar) ValueStack(com.opensymphony.xwork2.util.ValueStack) Foo(com.opensymphony.xwork2.util.Foo)

Aggregations

HashMap (java.util.HashMap)17 Bar (com.opensymphony.xwork2.util.Bar)14 Foo (com.opensymphony.xwork2.util.Foo)13 ValueStack (com.opensymphony.xwork2.util.ValueStack)12 ActionProxy (com.opensymphony.xwork2.ActionProxy)9 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)9 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)7 ValidationAware (com.opensymphony.xwork2.interceptor.ValidationAware)7 List (java.util.List)6 Map (java.util.Map)6 ConversionData (com.opensymphony.xwork2.conversion.impl.ConversionData)5 Mock (com.mockobjects.dynamic.Mock)4 ActionContext (com.opensymphony.xwork2.ActionContext)4 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)4 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)3 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)3 MockResult (com.opensymphony.xwork2.mock.MockResult)3 ModelDrivenAction2 (com.opensymphony.xwork2.test.ModelDrivenAction2)3 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)3 ActionSupport (com.opensymphony.xwork2.ActionSupport)2