在WebWork2.2中和Spring的结合变得简单了,WebWork的Action的也可以由Spring来管理。但是如何进行测试了,在google上搜了一下,其代码都是如下形式:
1 Map params = new HashMap();
2 params.put("a", "test");
3 Map paramCtx = new HashMap();
4 paramCtx.put(ActionContext.PARAMETERS, params);
5 ActionProxy proxy = ActionProxyFactory.getFactory().createActionProxy("/organiz", "new_depart", paramCtx, false, false);
6 proxy.setExecuteResult(false);
7 assertEquals(proxy.execute(), "success");
8
9 MyTestAction action = (MyTestAction) proxy.getAction();
10 assertEquals(action.getA(), "test");
该代码执行时会报错误,查看了一下源代码应该加入
1paramCtx.put(ActionContext.DEV_MODE, Boolean.FALSE);
其次需要加载spring的applicationContext,代码如下:
1SpringObjectFactory objectFactory = new SpringObjectFactory();
2 ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
3 objectFactory.setApplicationContext(appContext);
4 ObjectFactory.setObjectFactory(objectFactory);
posted @
2012-02-28 22:53 小小~咖啡豆 阅读(181) |
评论 (0) |
编辑 收藏
1.编译乱码,设置编译的字符集编码和环境编码
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
设置环境变量MAVEN_OPTS=-Xms64m -Xmx128m -Dfile.encoding=UTF-8
2.运行mvn test时乱码(IDE上运行TestCase时OK,但是运行maven test乱码,结果测试不通过)修改pom.xml增加如下内容即可
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Dfile.encoding=UTF-8</argLine>
<systemProperties>
<property>
<name>net.sourceforge.cobertura.datafile</name>
<value>target/cobertura/cobertura.ser</value>
</property>
</systemProperties>
</configuration>
</plugin>
posted @
2011-06-30 02:15 小小~咖啡豆 阅读(1516) |
评论 (1) |
编辑 收藏