Search in sources :

Example 1 with StubConfigurationProvider

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

the class OgnlUtilTest method reloadTestContainerConfiguration.

private void reloadTestContainerConfiguration(boolean allowStaticField) {
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            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 2 with StubConfigurationProvider

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

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

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

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

the class ConfigurationTest method testInitForPackageProviders.

public void testInitForPackageProviders() {
    loadConfigurationProviders(new StubConfigurationProvider() {

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.factory(PackageProvider.class, "foo", MyPackageProvider.class);
        }
    });
    assertEquals(configuration, MyPackageProvider.getConfiguration());
}
Also used : ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) StubConfigurationProvider(com.opensymphony.xwork2.test.StubConfigurationProvider) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Aggregations

ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)10 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)10 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)10 ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)9 Context (com.opensymphony.xwork2.inject.Context)3 Factory (com.opensymphony.xwork2.inject.Factory)3 ActionContext (com.opensymphony.xwork2.ActionContext)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 ActionProxyFactory (com.opensymphony.xwork2.ActionProxyFactory)1 DefaultActionProxyFactory (com.opensymphony.xwork2.DefaultActionProxyFactory)1 LocalizedTextProvider (com.opensymphony.xwork2.LocalizedTextProvider)1 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)1 TextProvider (com.opensymphony.xwork2.TextProvider)1 ConfigurationProvider (com.opensymphony.xwork2.config.ConfigurationProvider)1 DummyTextProvider (com.opensymphony.xwork2.mock.DummyTextProvider)1 Bar (com.opensymphony.xwork2.util.Bar)1 Cat (com.opensymphony.xwork2.util.Cat)1