Search in sources :

Example 41 with Bar

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

the class ConfigurationTest method testWildcardName.

public void testWildcardName() {
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    ActionConfig config = configuration.getActionConfig("", "WildCard/Simple/input");
    assertNotNull(config);
    assertTrue("Wrong class name, " + config.getClassName(), "com.opensymphony.xwork2.SimpleAction".equals(config.getClassName()));
    assertTrue("Wrong method name", "input".equals(config.getMethodName()));
    Map<String, String> p = config.getParams();
    assertTrue("Wrong parameter, " + p.get("foo"), "Simple".equals(p.get("foo")));
    assertTrue("Wrong parameter, " + p.get("bar"), "input".equals(p.get("bar")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig)

Example 42 with Bar

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

the class ConfigurationTest method testMultipleConfigProviders.

public void testMultipleConfigProviders() {
    configurationManager.addContainerProvider(new MockConfigurationProvider());
    try {
        configurationManager.reload();
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail();
    }
    RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
    // check that it has configuration from xml
    assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
    // check that it has configuration from MockConfigurationProvider
    assertNotNull(configuration.getActionConfig("", MockConfigurationProvider.FOO_ACTION_NAME));
}
Also used : MockConfigurationProvider(com.opensymphony.xwork2.config.providers.MockConfigurationProvider)

Example 43 with Bar

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

the class ConfigurationTest method testMultipleContainerProviders.

public void testMultipleContainerProviders() throws Exception {
    // to start from scratch
    configurationManager.destroyConfiguration();
    // to build basic configuration
    configurationManager.getConfiguration();
    Mock mockContainerProvider = new Mock(ContainerProvider.class);
    mockContainerProvider.expect("init", C.ANY_ARGS);
    mockContainerProvider.expect("register", C.ANY_ARGS);
    mockContainerProvider.matchAndReturn("equals", C.ANY_ARGS, false);
    mockContainerProvider.matchAndReturn("toString", "foo");
    mockContainerProvider.matchAndReturn("destroy", null);
    mockContainerProvider.expectAndReturn("needsReload", true);
    // the order of providers must be changed as just first is checked if reload is needed
    configurationManager.addContainerProvider((ContainerProvider) mockContainerProvider.proxy());
    XmlConfigurationProvider provider = new StrutsXmlConfigurationProvider("xwork-sample.xml");
    container.inject(provider);
    configurationManager.addContainerProvider(provider);
    Configuration config = null;
    try {
        config = configurationManager.getConfiguration();
    } catch (ConfigurationException e) {
        e.printStackTrace();
        fail();
    }
    RuntimeConfiguration configuration = config.getRuntimeConfiguration();
    // check that it has configuration from xml
    assertNotNull(configuration.getActionConfig("/foo/bar", "Bar"));
    mockContainerProvider.verify();
}
Also used : StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) Mock(com.mockobjects.dynamic.Mock)

Example 44 with Bar

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

the class ConfigurationTest method testInterceptorParamInehritanceOverride.

public void testInterceptorParamInehritanceOverride() {
    try {
        ActionProxy proxy = actionProxyFactory.createActionProxy("/foo/bar", "TestInterceptorParamInehritanceOverride", null, null);
        assertEquals(1, proxy.getConfig().getInterceptors().size());
        MockInterceptor testInterceptor = (MockInterceptor) proxy.getConfig().getInterceptors().get(0).getInterceptor();
        assertEquals("foo123", testInterceptor.getExpectedFoo());
        proxy.execute();
        assertTrue(testInterceptor.isExecuted());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : ActionProxy(com.opensymphony.xwork2.ActionProxy) MockInterceptor(com.opensymphony.xwork2.mock.MockInterceptor)

Example 45 with Bar

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

the class ActionConfigMatcherTest method testLooseMatch.

public void testLooseMatch() {
    configMap.put("*!*", configMap.get("bar/*/**"));
    ActionConfigMatcher matcher = new ActionConfigMatcher(new WildcardHelper(), configMap, true);
    // exact match
    ActionConfig m = matcher.match("foo/class/method");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced " + m.getClassName(), "foo.bar.classAction".equals(m.getClassName()));
    assertTrue("Method hasn't been replaced", "domethod".equals(m.getMethodName()));
    // Missing last wildcard
    m = matcher.match("foo/class");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced", "foo.bar.classAction".equals(m.getClassName()));
    assertTrue("Method hasn't been replaced, " + m.getMethodName(), "do".equals(m.getMethodName()));
    // Simple mapping
    m = matcher.match("class!method");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced, " + m.getPackageName(), "package-class".equals(m.getPackageName()));
    assertTrue("Method hasn't been replaced", "method".equals(m.getParams().get("first")));
    // Simple mapping
    m = matcher.match("class");
    assertNotNull("ActionConfig should be matched", m);
    assertTrue("Class hasn't been replaced", "package-class".equals(m.getPackageName()));
    assertTrue("Method hasn't been replaced", "".equals(m.getParams().get("first")));
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) WildcardHelper(com.opensymphony.xwork2.util.WildcardHelper)

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