use of com.opensymphony.xwork2.config.impl.MockConfiguration in project struts by apache.
the class XmlConfigurationProviderTest method testLoadOrder.
public void testLoadOrder() throws Exception {
configuration = new MockConfiguration();
((MockConfiguration) configuration).selfRegister();
container = configuration.getContainer();
XmlConfigurationProvider prov = new StrutsXmlConfigurationProvider("xwork-test-load-order.xml") {
@Override
protected Iterator<URL> getConfigurationUrls(String fileName) throws IOException {
List<URL> urls = new ArrayList<>();
urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder1/xwork-test-load-order.xml", XmlConfigurationProvider.class));
urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder2/xwork-test-load-order.xml", XmlConfigurationProvider.class));
urls.add(ClassLoaderUtil.getResource("com/opensymphony/xwork2/config/providers/loadorder3/xwork-test-load-order.xml", XmlConfigurationProvider.class));
return urls.iterator();
}
};
prov.setObjectFactory(container.getInstance(ObjectFactory.class));
prov.setFileManagerFactory(container.getInstance(FileManagerFactory.class));
prov.init(configuration);
List<Document> docs = prov.getDocuments();
assertEquals(3, docs.size());
assertEquals(1, XmlHelper.getLoadOrder(docs.get(0)).intValue());
assertEquals(2, XmlHelper.getLoadOrder(docs.get(1)).intValue());
assertEquals(3, XmlHelper.getLoadOrder(docs.get(2)).intValue());
}
use of com.opensymphony.xwork2.config.impl.MockConfiguration in project struts by apache.
the class DispatcherTest method testInterceptorDestroy.
public void testInterceptorDestroy() throws Exception {
Mock mockInterceptor = new Mock(Interceptor.class);
mockInterceptor.matchAndReturn("hashCode", 0);
mockInterceptor.expect("destroy");
InterceptorMapping interceptorMapping = new InterceptorMapping("test", (Interceptor) mockInterceptor.proxy());
InterceptorStackConfig isc = new InterceptorStackConfig.Builder("test").addInterceptor(interceptorMapping).build();
PackageConfig packageConfig = new PackageConfig.Builder("test").addInterceptorStackConfig(isc).build();
Map<String, PackageConfig> packageConfigs = new HashMap<String, PackageConfig>();
packageConfigs.put("test", packageConfig);
Mock mockContainer = new Mock(Container.class);
mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new ObjectFactory());
String reloadConfigs = container.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)), reloadConfigs);
Mock mockConfiguration = new Mock(Configuration.class);
mockConfiguration.matchAndReturn("getPackageConfigs", packageConfigs);
mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expect("destroy");
ConfigurationManager configurationManager = new ConfigurationManager(Container.DEFAULT_NAME);
configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());
Dispatcher dispatcher = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), configurationManager);
dispatcher.init();
dispatcher.cleanup();
mockInterceptor.verify();
mockContainer.verify();
mockConfiguration.verify();
}
use of com.opensymphony.xwork2.config.impl.MockConfiguration in project struts by apache.
the class TestNGXWorkTestCase method setUp.
@BeforeTest
protected void setUp() throws Exception {
configurationManager = XWorkTestCaseHelper.setUp();
configuration = new MockConfiguration();
((MockConfiguration) configuration).selfRegister();
container = configuration.getContainer();
actionProxyFactory = container.getInstance(ActionProxyFactory.class);
}
use of com.opensymphony.xwork2.config.impl.MockConfiguration in project struts by apache.
the class DispatcherTest method testObjectFactoryDestroy.
public void testObjectFactoryDestroy() throws Exception {
ConfigurationManager cm = new ConfigurationManager(Container.DEFAULT_NAME);
Dispatcher du = new MockDispatcher(new MockServletContext(), new HashMap<String, String>(), cm);
Mock mockConfiguration = new Mock(Configuration.class);
cm.setConfiguration((Configuration) mockConfiguration.proxy());
Mock mockContainer = new Mock(Container.class);
String reloadConfigs = container.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD);
mockContainer.expectAndReturn("getInstance", C.args(C.eq(String.class), C.eq(StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD)), reloadConfigs);
final InnerDestroyableObjectFactory destroyedObjectFactory = new InnerDestroyableObjectFactory();
destroyedObjectFactory.setContainer((Container) mockContainer.proxy());
mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
mockConfiguration.expect("destroy");
mockConfiguration.matchAndReturn("getPackageConfigs", new HashMap<String, PackageConfig>());
du.init();
assertFalse(destroyedObjectFactory.destroyed);
du.cleanup();
assertTrue(destroyedObjectFactory.destroyed);
mockConfiguration.verify();
mockContainer.verify();
}
use of com.opensymphony.xwork2.config.impl.MockConfiguration in project struts by apache.
the class StrutsJavaConfigurationProviderTest method testRegister.
@Test
public void testRegister() throws Exception {
final ConstantConfig constantConfig = new ConstantConfig();
constantConfig.setDevMode(true);
final String expectedUnknownHandler = "expectedUnknownHandler";
StrutsJavaConfiguration javaConfig = new StrutsJavaConfiguration() {
@Override
public List<String> unknownHandlerStack() {
return Collections.singletonList(expectedUnknownHandler);
}
@Override
public List<ConstantConfig> constants() {
return Collections.singletonList(constantConfig);
}
@Override
public List<BeanConfig> beans() {
return Arrays.asList(new BeanConfig(TestBean.class, "struts"), new BeanConfig(TestBean.class, "struts.static", TestBean.class, Scope.PROTOTYPE, true, true), new BeanConfig(TestBean.class, "struts.test.bean", TestBean.class));
}
@Override
public Optional<BeanSelectionConfig> beanSelection() {
return Optional.of(new BeanSelectionConfig(TestBeanSelectionProvider.class, "testBeans"));
}
};
StrutsJavaConfigurationProvider provider = new StrutsJavaConfigurationProvider(javaConfig);
Configuration configuration = new MockConfiguration();
provider.init(configuration);
ContainerBuilder builder = new ContainerBuilder();
LocatableProperties props = new LocatableProperties();
provider.register(builder, props);
// constant
Assert.assertEquals(String.valueOf(constantConfig.getDevMode()), props.get(StrutsConstants.STRUTS_DEVMODE));
// unknown-handler-stack
Assert.assertNotNull(configuration.getUnknownHandlerStack());
Assert.assertEquals(1, configuration.getUnknownHandlerStack().size());
Assert.assertEquals(expectedUnknownHandler, configuration.getUnknownHandlerStack().get(0).getName());
// bean
Container container = builder.create(true);
TestBean testBean = container.getInstance(TestBean.class);
Assert.assertNotNull(testBean);
testBean = container.getInstance(TestBean.class, "struts");
Assert.assertNotNull(testBean);
// bean selection
Set<String> names = container.getInstanceNames(TestBean.class);
Assert.assertTrue(names.contains("struts"));
Assert.assertTrue(names.contains("struts.test.bean"));
}
Aggregations