Search in sources :

Example 11 with LocatableProperties

use of com.opensymphony.xwork2.util.location.LocatableProperties 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)

Example 12 with LocatableProperties

use of com.opensymphony.xwork2.util.location.LocatableProperties 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)

Example 13 with LocatableProperties

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

the class DebugTagTest method setStrutsConstant.

/**
 * Overwrite the Struts Constant and reload container
 */
private void setStrutsConstant(final Map<String, String> overwritePropeties) {
    configurationManager.addContainerProvider(new StubConfigurationProvider() {

        @Override
        public boolean needsReload() {
            return true;
        }

        @Override
        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            for (Map.Entry<String, String> stringStringEntry : overwritePropeties.entrySet()) {
                props.setProperty(stringStringEntry.getKey(), stringStringEntry.getValue(), null);
            }
        }
    });
    configurationManager.reload();
    container = configurationManager.getConfiguration().getContainer();
    stack.getActionContext().withContainer(container);
}
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 14 with LocatableProperties

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

the class AnnotationValidationConfigurationBuilderTest method createValidationManager.

private AnnotationActionValidatorManager createValidationManager(final Class<? extends ActionSupport> actionClass, Locale locale) throws Exception {
    loadConfigurationProviders(new ConfigurationProvider() {

        public void destroy() {
        }

        public void init(Configuration configuration) throws ConfigurationException {
            configuration.addPackageConfig("default", new PackageConfig.Builder("default").addActionConfig("annotation", new ActionConfig.Builder("", "annotation", actionClass.getName()).build()).build());
        }

        public boolean needsReload() {
            return false;
        }

        public void loadPackages() throws ConfigurationException {
        }

        public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
            builder.constant(StrutsConstants.STRUTS_DEVMODE, true);
        }
    });
    // ActionContext is destroyed during rebuilding configuration
    ActionContext.getContext().withLocale(locale);
    ActionInvocation invocation = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), true);
    container.inject(invocation);
    invocation.init(actionProxyFactory.createActionProxy("", "annotation", null, ActionContext.getContext().getContextMap()));
    AnnotationActionValidatorManager manager = new AnnotationActionValidatorManager();
    container.inject(manager);
    ValidatorFactory vf = container.getInstance(ValidatorFactory.class);
    vf.registerValidator("myValidator", MyValidator.class.getName());
    return manager;
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) Configuration(com.opensymphony.xwork2.config.Configuration) ConfigurationProvider(com.opensymphony.xwork2.config.ConfigurationProvider) DefaultActionInvocation(com.opensymphony.xwork2.DefaultActionInvocation) ActionInvocation(com.opensymphony.xwork2.ActionInvocation) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) DefaultActionInvocation(com.opensymphony.xwork2.DefaultActionInvocation) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) LocatableProperties(com.opensymphony.xwork2.util.location.LocatableProperties)

Example 15 with LocatableProperties

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

the class PropertiesConfigurationProviderTest method testRegister_DifferentLocale.

public void testRegister_DifferentLocale() {
    ContainerBuilder builder = new ContainerBuilder();
    builder.constant("foo", "bar");
    builder.constant("struts.locale", "de_DE");
    PropertiesConfigurationProvider prov = new PropertiesConfigurationProvider();
    prov.register(builder, new LocatableProperties());
    Container container = builder.create(true);
    String localeStr = container.getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
    Locale locale = LocaleUtils.toLocale(localeStr);
    assertNotNull(locale);
    assertEquals("DE", locale.getCountry());
    assertEquals("de", locale.getLanguage());
}
Also used : Locale(java.util.Locale) Container(com.opensymphony.xwork2.inject.Container) ContainerBuilder(com.opensymphony.xwork2.inject.ContainerBuilder) 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