Search in sources :

Example 1 with StrutsDefaultConfigurationProvider

use of com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider in project struts by apache.

the class XWorkTestCaseHelper method loadConfigurationProviders.

public static ConfigurationManager loadConfigurationProviders(ConfigurationManager configurationManager, ConfigurationProvider... providers) {
    try {
        tearDown(configurationManager);
    } catch (Exception e) {
        throw new RuntimeException("Cannot clean old configuration", e);
    }
    configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
    configurationManager.addContainerProvider(new ContainerProvider() {

        public void destroy() {
        }

        public void init(Configuration configuration) throws ConfigurationException {
        }

        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.setAllowDuplicates(true);
        }
    });
    configurationManager.addContainerProvider(new StrutsDefaultConfigurationProvider());
    for (ConfigurationProvider prov : providers) {
        if (prov instanceof XmlConfigurationProvider) {
            ((XmlConfigurationProvider) prov).setThrowExceptionOnDuplicateBeans(false);
        }
        configurationManager.addContainerProvider(prov);
    }
    Container container = configurationManager.getConfiguration().getContainer();
    // Reset the value stack
    ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
    stack.getActionContext().withContainer(container).withValueStack(stack).bind();
    return configurationManager;
}
Also used : XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider) XmlConfigurationProvider(com.opensymphony.xwork2.config.providers.XmlConfigurationProvider) Container(com.opensymphony.xwork2.inject.Container) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)

Example 2 with StrutsDefaultConfigurationProvider

use of com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderInterceptorParamOverridingTest method testInterceptorParamOveriding.

public void testInterceptorParamOveriding() throws Exception {
    DefaultConfiguration conf = new DefaultConfiguration();
    final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-param-overriding.xml");
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    p.setFileManagerFactory(factory);
    conf.reloadContainer(new ArrayList<ContainerProvider>() {

        {
            add(new StrutsDefaultConfigurationProvider());
            add(p);
        }
    });
    RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
    ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
    ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
    List<InterceptorMapping> actionOneInterceptors = actionOne.getInterceptors();
    List<InterceptorMapping> actionTwoInterceptors = actionTwo.getInterceptors();
    assertNotNull(actionOne);
    assertNotNull(actionTwo);
    assertNotNull(actionOneInterceptors);
    assertNotNull(actionTwoInterceptors);
    assertEquals(actionOneInterceptors.size(), 3);
    assertEquals(actionTwoInterceptors.size(), 3);
    InterceptorMapping actionOneInterceptorMapping1 = actionOneInterceptors.get(0);
    InterceptorMapping actionOneInterceptorMapping2 = actionOneInterceptors.get(1);
    InterceptorMapping actionOneInterceptorMapping3 = actionOneInterceptors.get(2);
    InterceptorMapping actionTwoInterceptorMapping1 = actionTwoInterceptors.get(0);
    InterceptorMapping actionTwoInterceptorMapping2 = actionTwoInterceptors.get(1);
    InterceptorMapping actionTwoInterceptorMapping3 = actionTwoInterceptors.get(2);
    assertNotNull(actionOneInterceptorMapping1);
    assertNotNull(actionOneInterceptorMapping2);
    assertNotNull(actionOneInterceptorMapping3);
    assertNotNull(actionTwoInterceptorMapping1);
    assertNotNull(actionTwoInterceptorMapping2);
    assertNotNull(actionTwoInterceptorMapping3);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) ContainerProvider(com.opensymphony.xwork2.config.ContainerProvider) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 3 with StrutsDefaultConfigurationProvider

use of com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider in project struts by apache.

the class XmlConfigurationProviderInterceptorStackParamOverridingTest method testInterceptorStackParamOveriding.

public void testInterceptorStackParamOveriding() throws Exception {
    DefaultConfiguration conf = new DefaultConfiguration();
    final XmlConfigurationProvider p = new StrutsXmlConfigurationProvider("com/opensymphony/xwork2/config/providers/xwork-test-interceptor-stack-param-overriding.xml");
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    p.setFileManagerFactory(factory);
    configurationManager.addContainerProvider(p);
    conf.reloadContainer(new ArrayList<ContainerProvider>() {

        {
            add(new StrutsDefaultConfigurationProvider());
            add(p);
        }
    });
    RuntimeConfiguration rtConf = conf.getRuntimeConfiguration();
    ActionConfig actionOne = rtConf.getActionConfig("", "actionOne");
    ActionConfig actionTwo = rtConf.getActionConfig("", "actionTwo");
    List actionOneInterceptors = actionOne.getInterceptors();
    List actionTwoInterceptors = actionTwo.getInterceptors();
    assertNotNull(actionOne);
    assertNotNull(actionTwo);
    assertNotNull(actionOneInterceptors);
    assertNotNull(actionTwoInterceptors);
    assertEquals(actionOneInterceptors.size(), 3);
    assertEquals(actionTwoInterceptors.size(), 3);
    InterceptorMapping actionOneInterceptorMapping1 = (InterceptorMapping) actionOneInterceptors.get(0);
    InterceptorMapping actionOneInterceptorMapping2 = (InterceptorMapping) actionOneInterceptors.get(1);
    InterceptorMapping actionOneInterceptorMapping3 = (InterceptorMapping) actionOneInterceptors.get(2);
    InterceptorMapping actionTwoInterceptorMapping1 = (InterceptorMapping) actionTwoInterceptors.get(0);
    InterceptorMapping actionTwoInterceptorMapping2 = (InterceptorMapping) actionTwoInterceptors.get(1);
    InterceptorMapping actionTwoInterceptorMapping3 = (InterceptorMapping) actionTwoInterceptors.get(2);
    assertNotNull(actionOneInterceptorMapping1);
    assertNotNull(actionOneInterceptorMapping2);
    assertNotNull(actionOneInterceptorMapping3);
    assertNotNull(actionTwoInterceptorMapping1);
    assertNotNull(actionTwoInterceptorMapping2);
    assertNotNull(actionTwoInterceptorMapping3);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamOne(), "i1p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping1.getInterceptor()).getParamTwo(), "i1p2");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamOne(), "i2p1");
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping2.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionOneInterceptorMapping3.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping1.getInterceptor()).getParamTwo(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamOne(), null);
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping2.getInterceptor()).getParamTwo(), "i2p2");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamOne(), "i3p1");
    assertEquals(((InterceptorForTestPurpose) actionTwoInterceptorMapping3.getInterceptor()).getParamTwo(), "i3p2");
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) ContainerProvider(com.opensymphony.xwork2.config.ContainerProvider) ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) DefaultConfiguration(com.opensymphony.xwork2.config.impl.DefaultConfiguration) List(java.util.List) ArrayList(java.util.ArrayList) InterceptorMapping(com.opensymphony.xwork2.config.entities.InterceptorMapping) RuntimeConfiguration(com.opensymphony.xwork2.config.RuntimeConfiguration)

Example 4 with StrutsDefaultConfigurationProvider

use of com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider in project struts by apache.

the class ConfigurationManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    configurationManager.destroyConfiguration();
    configProviderMock = new Mock(ConfigurationProvider.class);
    configProviderMock.matchAndReturn("equals", C.ANY_ARGS, false);
    ConfigurationProvider mockProvider = (ConfigurationProvider) configProviderMock.proxy();
    configurationManager.addContainerProvider(new StrutsDefaultConfigurationProvider());
    configurationManager.addContainerProvider(mockProvider);
    // the first time it always inits
    configProviderMock.expect("init", C.isA(Configuration.class));
    configProviderMock.expect("register", C.ANY_ARGS);
    configProviderMock.expect("loadPackages", C.ANY_ARGS);
    configProviderMock.matchAndReturn("toString", "mock");
    configuration = configurationManager.getConfiguration();
}
Also used : StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider) StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider) Mock(com.mockobjects.dynamic.Mock)

Example 5 with StrutsDefaultConfigurationProvider

use of com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider in project struts by apache.

the class MockConfiguration method selfRegister.

public void selfRegister() {
    // this cannot be done in the constructor, as it causes an infinite loop
    builder.factory(Configuration.class, MockConfiguration.class, Scope.SINGLETON);
    LocatableProperties props = new LocatableProperties();
    new StrutsDefaultConfigurationProvider().register(builder, props);
    builder.constant(StrutsConstants.STRUTS_DEVMODE, "false");
    builder.constant(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD, "true");
    builder.constant(StrutsConstants.STRUTS_OGNL_ENABLE_EXPRESSION_CACHE, "true");
    builder.constant(StrutsConstants.STRUTS_ENABLE_DYNAMIC_METHOD_INVOCATION, "false");
    container = builder.create(true);
}
Also used : LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)

Aggregations

StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)8 StrutsXmlConfigurationProvider (org.apache.struts2.config.StrutsXmlConfigurationProvider)6 OgnlValueStack (com.opensymphony.xwork2.ognl.OgnlValueStack)4 ValueStack (com.opensymphony.xwork2.util.ValueStack)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)3 ContainerProvider (com.opensymphony.xwork2.config.ContainerProvider)2 RuntimeConfiguration (com.opensymphony.xwork2.config.RuntimeConfiguration)2 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)2 DefaultConfiguration (com.opensymphony.xwork2.config.impl.DefaultConfiguration)2 Container (com.opensymphony.xwork2.inject.Container)2 DefaultFileManager (com.opensymphony.xwork2.util.fs.DefaultFileManager)2 DefaultFileManagerFactory (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory)2 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)2 Mock (com.mockobjects.dynamic.Mock)1 Configuration (com.opensymphony.xwork2.config.Configuration)1 ConfigurationManager (com.opensymphony.xwork2.config.ConfigurationManager)1 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)1 ResultConfig (com.opensymphony.xwork2.config.entities.ResultConfig)1