Search in sources :

Example 6 with Factory

use of com.opensymphony.xwork2.inject.Factory 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 7 with Factory

use of com.opensymphony.xwork2.inject.Factory 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 8 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class ScopedModelDrivenInterceptorTest method setUp.

/**
 * Set up instance variables required by this test case.
 */
@Override
public void setUp() throws Exception {
    super.setUp();
    inter = new ScopedModelDrivenInterceptor();
    ProxyObjectFactory factory = new ProxyObjectFactory();
    factory.setContainer(container);
    inter.setObjectFactory(factory);
}
Also used : ProxyObjectFactory(com.opensymphony.xwork2.ProxyObjectFactory)

Example 9 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class DefaultActionValidatorManagerTest method setUp.

@Override
protected void setUp() throws Exception {
    actionValidatorManager = new DefaultActionValidatorManager();
    super.setUp();
    mockValidatorFileParser = new Mock(ValidatorFileParser.class);
    actionValidatorManager.setValidatorFileParser((ValidatorFileParser) mockValidatorFileParser.proxy());
    mockValidatorFactory = new Mock(ValidatorFactory.class);
    actionValidatorManager.setValidatorFactory((ValidatorFactory) mockValidatorFactory.proxy());
    stubValueStack = new StubValueStack();
    ActionContext.of(new HashMap<>()).withValueStack(stubValueStack).bind();
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    factory.setContainer(container);
    factory.setFileManager(new DefaultFileManager());
    actionValidatorManager.setFileManagerFactory(factory);
}
Also used : DefaultFileManagerFactory(com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory) StubValueStack(com.opensymphony.xwork2.StubValueStack) DefaultFileManager(com.opensymphony.xwork2.util.fs.DefaultFileManager) Mock(com.mockobjects.dynamic.Mock)

Example 10 with Factory

use of com.opensymphony.xwork2.inject.Factory in project struts by apache.

the class DummyFileManager method testFileManagerFactoryWithRealConfig.

public void testFileManagerFactoryWithRealConfig() throws Exception {
    // given
    DefaultFileManagerFactory factory = new DefaultFileManagerFactory();
    container.inject(factory);
    // when
    FileManager fm = factory.getFileManager();
    // then
    assertTrue(fm instanceof DefaultFileManager);
}
Also used : FileManager(com.opensymphony.xwork2.FileManager)

Aggregations

ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)10 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)7 ValueStack (com.opensymphony.xwork2.util.ValueStack)5 DefaultFileManagerFactory (com.opensymphony.xwork2.util.fs.DefaultFileManagerFactory)5 ActionProxyFactory (com.opensymphony.xwork2.ActionProxyFactory)4 InterceptorMapping (com.opensymphony.xwork2.config.entities.InterceptorMapping)4 Context (com.opensymphony.xwork2.inject.Context)4 ArrayList (java.util.ArrayList)4 StrutsException (org.apache.struts2.StrutsException)4 ActionContext (com.opensymphony.xwork2.ActionContext)3 DefaultActionProxyFactory (com.opensymphony.xwork2.DefaultActionProxyFactory)3 FileManager (com.opensymphony.xwork2.FileManager)3 ContainerBuilder (com.opensymphony.xwork2.inject.ContainerBuilder)3 Factory (com.opensymphony.xwork2.inject.Factory)3 StubConfigurationProvider (com.opensymphony.xwork2.test.StubConfigurationProvider)3 DefaultFileManager (com.opensymphony.xwork2.util.fs.DefaultFileManager)3 LocatableProperties (com.opensymphony.xwork2.util.location.LocatableProperties)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3