Search in sources :

Example 6 with LocatableProperties

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

the class OgnlValueStackTest method reloadTestContainerConfiguration.

private void reloadTestContainerConfiguration(Boolean allowStaticMethod, Boolean allowStaticField) throws Exception {
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            // undefined values then should be evaluated to false
            if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS)) {
                props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS);
            }
            if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS)) {
                props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS);
            }
            if (allowStaticMethod != null) {
                props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, "" + allowStaticMethod);
            }
            if (allowStaticField != null) {
                props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS, "" + allowStaticField);
            }
        }
    });
    ognlUtil = container.getInstance(OgnlUtil.class);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 7 with LocatableProperties

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

the class PrefixBasedActionProxyFactoryTest method setUp.

@Override
public void setUp() throws Exception {
    ConfigurationProvider[] providers = new ConfigurationProvider[] { new StrutsXmlConfigurationProvider("xwork-sample.xml"), new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ActionProxyFactory.class, "prefix1", new Factory() {

                public Object create(Context context) throws Exception {
                    return new Prefix1Factory();
                }

                public Class type() {
                    return Prefix1Factory.class;
                }
            }, Scope.SINGLETON);
        }
    }, new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(ActionProxyFactory.class, "prefix2", new Factory() {

                public Object create(Context context) throws Exception {
                    return new Prefix2Factory();
                }

                public Class type() {
                    return Prefix2Factory.class;
                }
            }, Scope.SINGLETON);
        }
    } };
    loadConfigurationProviders(providers);
    factory = new PrefixBasedActionProxyFactory();
    factory.setContainer(container);
}
Also used : Context(com.opensymphony.xwork2.inject.Context) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) StrutsXmlConfigurationProvider(org.apache.struts2.config.StrutsXmlConfigurationProvider) Factory(com.opensymphony.xwork2.inject.Factory) ActionProxyFactory(com.opensymphony.xwork2.ActionProxyFactory) DefaultActionProxyFactory(com.opensymphony.xwork2.DefaultActionProxyFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Example 8 with LocatableProperties

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

the class PropertiesConfigurationProviderTest method testRegister_NoLocale.

public void testRegister_NoLocale() {
    ContainerBuilder builder = new ContainerBuilder();
    builder.constant("foo", "bar");
    PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider();
    prov.register(builder, new LocatableProperties());
    Container container = builder.create(true);
    String localeStr = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
    assertNull(localeStr);
}
Also used : Container(com.opensymphony.xwork2.inject.Container) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Example 9 with LocatableProperties

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

the class SpringObjectFactoryTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    sac = new StaticApplicationContext();
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            // No registered beans during initialization; They will be registered in each test, runtime.
            props.setProperty("applicationContextPath", "com/opensymphony/xwork2/spring/emptyContext-spring.xml");
            builder.factory(TextProvider.class, DummyTextProvider.class);
            builder.factory(ObjectFactory.class, SpringObjectFactory.class);
        }
    });
    objectFactory = (SpringObjectFactory) container.getInstance(ObjectFactory.class);
    objectFactory.setApplicationContext(sac);
    objectFactory.setAlwaysRespectAutowireStrategy(false);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) DummyTextProvider(com.opensymphony.xwork2.mock.DummyTextProvider) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) DummyTextProvider(com.opensymphony.xwork2.mock.DummyTextProvider) TextProvider(com.opensymphony.xwork2.TextProvider)

Example 10 with LocatableProperties

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

the class ConfigurationManagerTest method testDestroyConfiguration.

public void testDestroyConfiguration() throws Exception {
    class State {

        public boolean isDestroyed1 = false;

        public boolean isDestroyed2 = false;
    }
    final State state = new State();
    ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
    configurationManager.addContainerProvider(new ConfigurationProvider() {

        public void destroy() {
            throw new RuntimeException("testing testing 123");
        }

        public void init(Configuration configuration) throws ConfigurationException {
        }

        public void loadPackages() throws ConfigurationException {
        }

        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
        }
    });
    configurationManager.addContainerProvider(new ConfigurationProvider() {

        public void destroy() {
            state.isDestroyed1 = true;
        }

        public void init(Configuration configuration) throws ConfigurationException {
        }

        public void loadPackages() throws ConfigurationException {
        }

        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
        }
    });
    configurationManager.addContainerProvider(new ConfigurationProvider() {

        public void destroy() {
            throw new RuntimeException("testing testing 123");
        }

        public void init(Configuration configuration) throws ConfigurationException {
        }

        public void loadPackages() throws ConfigurationException {
        }

        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
        }
    });
    configurationManager.addContainerProvider(new ConfigurationProvider() {

        public void destroy() {
            state.isDestroyed2 = true;
        }

        public void init(Configuration configuration) throws ConfigurationException {
        }

        public void loadPackages() throws ConfigurationException {
        }

        public boolean needsReload() {
            return false;
        }

        public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
        }
    });
    assertFalse(state.isDestroyed1);
    assertFalse(state.isDestroyed2);
    configurationManager.clearContainerProviders();
    assertTrue(state.isDestroyed1);
    assertTrue(state.isDestroyed2);
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties) StrutsDefaultConfigurationProvider(com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider) Properties(java.util.Properties) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Aggregations

LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)19 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)18 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)15 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)10 Container (com.opensymphony.xwork2.inject.Container)4 Context (com.opensymphony.xwork2.inject.Context)4 Configuration (com.opensymphony.xwork2.config.Configuration)3 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)3 StrutsDefaultConfigurationProvider (com.opensymphony.xwork2.config.providers.StrutsDefaultConfigurationProvider)3 Factory (com.opensymphony.xwork2.inject.Factory)3 ActionContext (com.opensymphony.xwork2.ActionContext)2 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)2 BeanSelectionProvider (com.opensymphony.xwork2.config.BeanSelectionProvider)2 UnknownHandlerConfig (com.opensymphony.xwork2.config.entities.UnknownHandlerConfig)2 ObjectTypeDeterminer (com.opensymphony.xwork2.conversion.ObjectTypeDeterminer)2 MockObjectTypeDeterminer (com.opensymphony.xwork2.mock.MockObjectTypeDeterminer)2 Foo (com.opensymphony.xwork2.util.Foo)2 ValueStack (com.opensymphony.xwork2.util.ValueStack)2 Location (com.opensymphony.xwork2.util.location.Location)2 ArrayList (java.util.ArrayList)2