在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");
該代碼執行時會報錯誤,查看了一下源代碼應該加入
1
paramCtx.put(ActionContext.DEV_MODE, Boolean.FALSE);
其次需要加載spring的applicationContext,代碼如下:
1
SpringObjectFactory objectFactory = new SpringObjectFactory();
2
ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
3
objectFactory.setApplicationContext(appContext);
4
ObjectFactory.setObjectFactory(objectFactory);
posted @
2012-02-28 22:53 小小~咖啡豆 閱讀(186) |
評論 (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 小小~咖啡豆 閱讀(1526) |
評論 (1) |
編輯 收藏