??xml version="1.0" encoding="utf-8" standalone="yes"?>色综合久久天天综合网,国产欧美日韩综合精品一区二区,黄色一区二区在线观看http://www.aygfsteel.com/wangzhouyu/zh-cnWed, 18 Jun 2025 21:48:00 GMTWed, 18 Jun 2025 21:48:00 GMT60WebWork2.2l合spring的Action试http://www.aygfsteel.com/wangzhouyu/archive/2012/02/28/370946.html小~咖啡?/dc:creator>小~咖啡?/author>Tue, 28 Feb 2012 14:53:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2012/02/28/370946.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/370946.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2012/02/28/370946.html#Feedback0http://www.aygfsteel.com/wangzhouyu/comments/commentRss/370946.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/370946.html在WebWork2.2中和Spring的结合变得简单了QW(xu)ebWork的Action的也可以由Spring来管理。但是如何进行测试了Q在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, falsefalse);
 6        proxy.setExecuteResult(false);
 7        assertEquals(proxy.execute(), "success");
 8
 9        MyTestAction action = (MyTestAction) proxy.getAction();
10        assertEquals(action.getA(), "test");

该代码执行时会报错误Q查看了一下源代码应该加入
1paramCtx.put(ActionContext.DEV_MODE, Boolean.FALSE);

其次需要加载spring的applicationContextQ代码如下:
1SpringObjectFactory objectFactory = new SpringObjectFactory();
2        ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
3        objectFactory.setApplicationContext(appContext);
4        ObjectFactory.setObjectFactory(objectFactory);




]]>
mavnqhttp://www.aygfsteel.com/wangzhouyu/archive/2011/06/30/353403.html小~咖啡?/dc:creator>小~咖啡?/author>Wed, 29 Jun 2011 18:15:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2011/06/30/353403.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/353403.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2011/06/30/353403.html#Feedback1http://www.aygfsteel.com/wangzhouyu/comments/commentRss/353403.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/353403.html1.~译qQ设|编译的字符集编码和环境~码
<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.q行mvn test时ؕ码(IDE上运行TestCase时OKQ但是运行maven testq,l果试不通过Q修改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>

]]>
梅花雨的屏蔽鼠标右键、Ctrl+n、shift+F10、F5h、退格键代码http://www.aygfsteel.com/wangzhouyu/archive/2008/09/23/230696.html小~咖啡?/dc:creator>小~咖啡?/author>Tue, 23 Sep 2008 08:12:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2008/09/23/230696.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/230696.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2008/09/23/230696.html#Feedback0http://www.aygfsteel.com/wangzhouyu/comments/commentRss/230696.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/230696.html </head>
<body onkeydown="KeyDown()"
oncontextmenu="event.returnValue=false">

<script language="Javascript"><!--
//屏蔽鼠标右键、Ctrl+n、shift+F10、F5h、退格键
//Author: meizz(梅花? 2002-6-18

function KeyDown(){
if ((window.event.altKey)&&
((window.event.keyCode==37)|| //屏蔽 Alt+ 方向?←
(window.event.keyCode==39))){ //屏蔽 Alt+ 方向?→
alert("不准你用ALT+方向键前q或后退|页Q?);
event.returnValue=false;
}

/* 注:q还不是真正地屏?Alt+ 方向键,
因ؓ Alt+ 方向键弹告框Ӟ按住 Alt 键不放,
用鼠标点掉警告框Q这U屏蔽方法就失效了。以后若
有哪位高手有真正屏蔽 Alt 键的Ҏ(gu)Q请告知?/

if ((event.keyCode==8) || //屏蔽退格删除键
(event.keyCode==116)|| //屏蔽 F5 h?
(event.ctrlKey && event.keyCode==82)){ //Ctrl + R
event.keyCode=0;
event.returnValue=false;
}
if ((event.ctrlKey)&&(event.keyCode==78)) //屏蔽 Ctrl+n
event.returnValue=false;
if ((event.shiftKey)&&(event.keyCode==121)) //屏蔽 shift+F10
event.returnValue=false;
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false; //屏蔽 shift 加鼠标左键新开一|页
if ((window.event.altKey)&&(window.event.keyCode==115)){ //屏蔽Alt+F4
window.showModelessDialog("about:blank","","dialogWidth:1px;dialogheight:1px");
return false;}
}
/* 另外可以?window.open 的方法屏?IE 的所有菜?
W一U方法:
window.open("你的.htm", "","toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=no,top=0,left=0")
W二U方法是打开一个全屏的面Q?
window.open("你的.asp", "", "fullscreen=yes")
*/
// --></script>
<h2 align=center>屏蔽鼠标右键、Ctrl+n、shift+F10、F5h、退格键</h2>
</body>
</html>

<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代? onClick= 'window.location = "view-source:" + window.location.href'></div>

]]>
Unitils开发指南(三)http://www.aygfsteel.com/wangzhouyu/archive/2008/08/25/224169.html小~咖啡?/dc:creator>小~咖啡?/author>Mon, 25 Aug 2008 07:11:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2008/08/25/224169.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/224169.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2008/08/25/224169.html#Feedback2http://www.aygfsteel.com/wangzhouyu/comments/commentRss/224169.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/224169.html数据库测?/font>

在创Z业应用的时候,数据层的单元试因ؓ其复杂性往往被遗弃,Unitils大大降低了测试的复杂性,使得数据库的试变得Ҏ(gu)q且易维护。已下介ldatabasemodule和dbunitmoduleq行数据库的单元试?/font>

用dbUnit理试数据

数据库的试应该在单元测试数据库上运行,单元试数据库给我们提供了一个完整的q有着很好l粒度控制的试数据QDbUnitModule是在dbunit的基上进一步的为数据库的测试提供数据集的支持?/font>

加蝲试数据?/font>

让我们以UserDAO中一个简单的Ҏ(gu)findByNameQ检查姓氏和名字Qؓ例子开始介l。他的单元测试如?

@DataSet

public class UserDAOTest extends UnitilsJUnit4 {

    @Test

    public void testFindByName() {

        User result = userDao.findByName("doe", "john");

        assertPropertyLenEquals("userName", "jdoe", result);

    }

    @Test

    public void testFindByMinimalAge() {

        List<User> result = userDao.findByMinimalAge(18);        

        assertPropertyLenEquals("firstName", Arrays.asList("jack"), result);

    }

}

    @DateSet 注解表示了测试需要寻找dbunit的数据集文gq行加蝲Q如果没有指明数据集的文件名Q则Unitils自动在class文g的同目录下加载文件名?nbsp;className.xml的数据集文g。(q种定义到class上面的数据集UCؓclassU别的数据集Q?/font>

    数据?nbsp;文g必须是dbunit的FlatXMLDataSet文g格式Q其中包含了所要测试的数据。测试数据库表中所有的内容会被删除,然后再插入数据集中的 数据。如果表不属于数据集中的Q哪么该表的数据不会被删除。你也可以明的加入一个空的表元素Q例?lt;MY_TABLE/>Q可以达到删?nbsp;试数据库表中内容的作用Q,如果要明指定一个空的|那么使用值[null]?/font>

   为UserDAOTest我们创徏一个数据集Qƈ攑֜UserDAOTest.class文g同目录下?/font>

<?xml version='1.0' encoding='UTF-8'?>

<dataset>

    <usergroup name="admin" />  

    <user userName="jdoe"  name="doe"   firstname="john"   userGroup="admin" />

    <usergroup name="sales" />    

    <user userName="smith" name="smith" userGroup="sales" />

    

</dataset>

   试q行的时候,首先删除掉usergroup表和user表中的所有内容,然后插入数据集中的内容。其中name为smith的firstname的值将会是null?/font>

   假设testFindByMinimalAge()Ҏ(gu)用一个特D的数据集而不是用classU别的数据集Q你可以定义一?/font>UserDAOTest.testFindByMinimalAge.xml 数据集文件ƈ攑֜试cȝclass文g同目录下?/font>

<?xml version='1.0' encoding='UTF-8'?>

<dataset>

    <user userName="jack" age="18" />

    <user userName="jim"  age="17" />

</dataset>

q时Q你在testFindByMinimalAge()Ҏ(gu)使用@DataSet注解Q他覆盖classU的数据?/font>

public class UserDAOTest extends UnitilsJUnit4 {

@Test

@DataSet("UserDAOTest.testFindByMinimalAge.xml")

public void testFindByMinimalAge() {

List<User> result = userDao.findByMinimalAge(18); 

assertPropertyLenEquals("firstName", Arrays.asList("jack"), result);

}

}

不要q多的用methodU的数据集,因ؓq多的数据集文g意味着你要花大量的旉ȝ护,你优先考虑的是使用classU的数据集?/font>

配置数据集加载策?/font>

~省情况下数据集被写入数据库采用的是clean insert{略。这意味着数据在被写入数据库的时候是会先删除数据集中有用的表的数据Q然后在数据集中的数据写入数据库。加载策略是可配额制的,我们通过修改DbUnitModule.DataSet.loadStrategy.default 的属性值来改变加蝲{略。假设我们在unitils.properties属性文件中加入以下内容Q?/font>

DbUnitModule.DataSet.loadStrategy.default=org.unitils.dbunit.datasetloadstrategy.InsertLoadStrategy 

q时加蝲{略qclean insert变成?/font>insertQ数据已l存在表中将不会被删除,试数据只是q行插入操作?/font>

加蝲{略也可以?/font>@DataSet的注解属性对单独的一些测试进行配|:

@DataSet(loadStrategy = InsertLoadStrategy.class) 

对于那些树ŞDbUnit的h来说Q配|加载策略实际上是使用不同?/font>DatabaseOperationQ以下是默认支持的加载策略方式:

CleanInsertLoadStrategy: 先删除dateSet中有兌的数据,然后再插入数据?/font>

InsertLoadStrategy: 只插入数据?/font>

RefreshLoadStrategy: 有同样key的数据更斎ͼ没有的插入?/font>

UpdateLoadStrategy: 有同样key的数据更斎ͼ没有的不做Q何操作?/font>

配置数据集工?/font>

 在Unitils中数据集文g采用?/font>multischema xml 格式Q这是DbUnits?/font>FlatXmlDataSet 格式的扩展。配|文件格式和文g的扩展可以采?/font>DataSetFactory ?/font>

虽然Unitils当前只支持一U数据格式,但是我们可以通过实现DataSetFactory来用其他文件格式?/font>当你想用excel而不是xml格式的时候,可以通过unitils.property中的DbUnitModule.DataSet.factory.default 属性和@DataSet 注解来创Z个DbUnit's XlsDataSet 实例?/font>

验证试l果

有些时候我们想在测试时完毕后用数据集来检查数据库中的内容QD个例子当执行完毕一个存储过E后你想查一下啊数据是否更新了没有?/font>

下面的例子表C的是禁用到一q内没有使用q的帐户

public class UserDAOTest extends UnitilsJUnit4 { 

    @Test @ExpectedDataSet 

    public void testInactivateOldAccounts() { 

        userDao.inactivateOldAccounts(); 

    } 

注意在testҎ(gu)上增加了一?/font>@ExpectedDataSet 注解。这指明unitils?/font>UserDAOTest.testInactivateOldAccounts-result.xml q个数据集的内容和数据库的内容进行比较?/font>

<?xml version='1.0' encoding='UTF-8'?> 

<dataset> 

    <user userName="jack" active="true" /> 

    <user userName="jim"  active="false" /> 

</dataset> 

Ҏ(gu)q个数据集,会查是否有两条和记录集的值相同的记录在数据库中。而其他的记录和表不理会?/font>

使用的是@DataSet 注解的话Q文件名可以明确指出Q如果文件名没有明确指出来,那么文g名将匚wclassName .methodName -result.xml 

使用用结果数据集Q加入新的数据集意味着更多的维护。替代方式是在代码中执行相同的检查(如用一个findactiveusers()Ҏ(gu)Q?/font>

使用多模式的数据?/font>

一个程序不单单只是q接一个数据库shema。Unitils采用了扩展的数据集xml来定义多schemas下的数据。以下就是一个读取数据到2个不同的schemas中的例子Q?/font>

<?xml version='1.0' encoding='UTF-8'?> 

<dataset xmlns="SCHEMA_A" xmlns:b="SCHEMA_B"> 

    <user id="1" userName="jack" />     

    <b:role id="1" roleName="admin" /> 

</dataset> 

在这个例子中我定义了两个schemasQ?/font>SCHEMA_A ?nbsp;SCHEMA_B?/font>W一个schemaQ?/font>SCHEMA_A 被连接到默认的xml命名I间中,W二个schemaQ?/font>SCHEMA_B 被连接到命名I间b。如果表xml元素的前~使用了命名空间bQ那么该表就是schema SCHEMA_B 中的Q如果没有用Q何的命名I间那么该表被认ؓ?/font>SCHEMA_A  

中的。以上例子中试数据定义了表SCHEMA_A.user ?/font>SCHEMA_B.role?/font>

如果在数据集中没有配|一个默认的命名I间Q那么将会采用在unitils.properties中的属?/font>database.schemaNames 的第一个g为默认的

database.schemaNames=SCHEMA_A, SCHEMA_B 

q个配置?/font>SCHEMA_A 作ؓ~省的schemaQ这样你可以化数据集的声明?/font>

<?xml version='1.0' encoding='UTF-8'?> 

<dataset xmlns:b="SCHEMA_B"> 

    <user id="1" userName="jack" />     

    <b:role id="1" roleName="admin" /> 

</dataset> 

q接试数据?/font> 

在以上所有的例子中,我们都有一仉要的事情没有做:当我们进行测试的时候,怎样q接数据库ƈ得到DataSourceQ?/font>

当测试套件的W一个测试数据库的案例运行的时候,Unitils会通过属性文件创Z?/font>DataSource 的实例来q接你单元测试时的数据库Q以后的试中都用这?/font>DataSource 实例。连接配|的详细内容如下Q?/font>

database.driverClassName=oracle.jdbc.driver.OracleDriver 

database.url=jdbc:oracle:thin:@yourmachine:1521:YOUR_DB 

database.userName=john 

database.password=secret 

database.schemaNames=test_john 

?/font>配置章节所说的那样Q你可以连接数据库的驱动类和url地址配置?/font>unitils.properties 中去Q而用户名Q密码以及schema可以配置?/font>unitils-local.properties 中去Q这样可以让开发h员连接到自己的单元测试数据库中进行测试而不会干预到其他的h?/font>

在属性或者setterҎ(gu)前用注?/font>@TestDataSource Q将会将DataSource 实例注入到测试实例中去,如果你想加入一些代码或者配|一下你的datasourceQ你可以做一个抽象类来实现该功能Q所有的试c都l承该类。一个简单的例子如下Q?/font>

public abstract class BaseDAOTest extends UnitilsJUnit4 { 

    @TestDataSource 

    private DataSource dataSource; 

     

    @Before     

    public void initializeDao() { 

        BaseDAO dao = getDaoUnderTest(); 

        dao.setDataSource(dataSource); 

    } 

    protected abstract BaseDAO getDaoUnderTest(); 

上面的例子采用了注解来取得一个datasource的引用,另外一U方式就是?/font>DatabaseUnitils.getDataSource() Ҏ(gu)来取得datasource?/font>

事务

Z不同的原因,我们的测试都是运行在一个事务中的,其中最重要的原因如下:

数据库的很多action都是在事务正常提交后才做Q如SELECT FOR UPDATE 和触发器

许多目在测试数据的时候都会填写一些测试数据,每个试q行都会修改或者更C数据Q当下一个测试运行的时候,都需要将数据回复到原有的状态?/font>

如果使用的是hibernate或者JPA的时候,都需要每个测试都q行在事务中Q保证系l的正常工作?/font>

~省情况下,事务理是disabled的,事务的默认行为我们可以通过属性文件的配置加以改变Q?/font>

DatabaseModule.Transactional.value.default=commit 

采用q个讄Q每个的试都将执行commitQ其他的属性D?/font>rollback ?/font>disabled 

我们也可以通过在测试类上用注?/font>@Transactional 来改变默认的事务讄Q如Q?/font>

@Transactional(TransactionMode.ROLLBACK) 

public class UserDaoTest extends UnitilsJUnit4 { 

通过q种class上注解的事务理Q可以让每个试都确保回滚,@Transactional 注解q可以承的Q因此我们可以将其放在父cMQ而不必每个子c都q行声明?/font>

.........

如果你用Unitils的spring支持Q见使用springq行试Q你如果配置了PlatformTransactionManager 的beanQ那么unitils会使用q个事务理?/font>



]]>
Lotusscript判断文g是否存在http://www.aygfsteel.com/wangzhouyu/archive/2008/07/04/212501.html小~咖啡?/dc:creator>小~咖啡?/author>Fri, 04 Jul 2008 02:06:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2008/07/04/212501.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/212501.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2008/07/04/212501.html#Feedback0http://www.aygfsteel.com/wangzhouyu/comments/commentRss/212501.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/212501.html If   Dir$(dirName,   ATTR_DIRECTORY)   =   ""   Then  
  'Directory   does   not   exist  
Else  
  'Directory   does   exist  
End   If  
2、用FileSystemObjectQ? 
Set   objFSO   =   CreateObject("Scripting.FileSystemObject")  
   
If   objFSO.FolderExists(dirName)   Then  
  'Directory   does   exist  
Else  
  'Directory   does   not   exist  
End   If

]]>
Unitils开发指南(二)http://www.aygfsteel.com/wangzhouyu/archive/2008/04/07/191137.html小~咖啡?/dc:creator>小~咖啡?/author>Sun, 06 Apr 2008 16:45:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2008/04/07/191137.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/191137.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2008/04/07/191137.html#Feedback2http://www.aygfsteel.com/wangzhouyu/comments/commentRss/191137.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/191137.htmlUnitils模块

配置

和大多数的项目一Punitils也需要一些配|,默认情况下有3个配|,每个配置都覆写前一个的配置

  1. unitils-default.properties 默认的配|,在unitils发行包中?/li>
  2. unitils.properties 可包含项目的全部配置
  3. unitils-local.properties 可以包含用户特定配置

W一个配|文件unitils-default.propertiesQ它包含了缺省值ƈ被包含在unitils的发行包中。我们没有必要对q个文gq行修改Q但它可以用来作参考?/p>

W二个配|文件unitils.propertiesQ它是我们需要进行配|的文gQƈ且能覆写~省的配|。D个例子,如果你的目使用的是oracle数据库,你可以创Z个unitils.properties文gq覆写相应的driver class和database url?/p>

database.driverClassName=oracle.jdbc.driver.OracleDriver
database.url=jdbc:oracle:thin:@yourmachine:1521:YOUR_DB

q个文gq不是必ȝQ但是一旦你创徏了一个,你就需要将该文件放|在目的classpath?/p>

最后一个文Ӟunitils-local.properties是可选的配置文gQ它可以覆写目的配|,用来定义开发者的具体讄QD个例子来_如果每个开发者都使用自己的数据库schemaQ你可以创Z个unitils-local.properties为每个用户配|自q数据库̎受密码和schema?/p>

database.userName=john
database.password=secret
database.schemaNames=test_john

每个unitils-local.properties文g应该攄在对应的用户文g夹中Q?em>System.getProperty("user.home")Q?/p>

本地文g名unitils-local.properties也可以通过配置文g定义Q在unitils.properties覆写unitils.configuration.localFileName可以?/p>

unitils.configuration.localFileName=projectTwo-local.properties

 

启用你的unitils

unitils的功能是依赖于基的测试框Ӟ要用unitils的功能,必denable他们Q这样做的目的也是ؓ了容易扩展。目前支持的框架有:

  1. JUnit3 Qorg.unitils.UnitilsJUnit3
  2. JUnit4 Qorg.unitils.UnitilsJUnit4
  3. TestNGQorg.unitils.UnitilsTestNG

举个例子Q如果用JUnit3Q你要用unitils

import org.unitils.UnitilsJUnit3;
public class MyTest extends UnitilsJUnit3 {
}

通常你将创徏你自q包含一些公p为的试基类Q如dataSource的注入,你可以让q个基类l承unitils试cR?/p>

当你使用的是JUnit4的话Q你也可是?em>@RunWith来代替承unitils试c?/p>

import org.junit.runner.RunWith;
import org.unitils.UnitilsJUnit4TestClassRunner;
@RunWith(UnitilsJUnit4TestClassRunner.class)
public class MyTest {
}

 

模块pȝ

在开始D例之前,让我们先了解一下unitils概念?/p>

unitils的结构被设计成了十分Ҏ(gu)扩展Q每个模块提供了一U服务,当执行Test的时候通过TestListener调用相应的服务?/p>

image

q种设计采用了一个统一的方式提供服务,如果你需要加入其他的服务Q无需L~测试基c(UnitilsJUnit4q些c)。要加入新的服务只需要添加一个新的模块ƈ在unitls配置文g中登记这个模块?/p>

目前unitils中所有有效的模块如下Q?/p>

  1. DatabaseModule 数据库单元测试的l护和连接池?/li>
  2. DbUnitModule 使用DBUnit来管理测试数据?/li>
  3. hibernatemodule 支持Hibernate的配|和自动数据库映检查?/li>
  4. EasyMockModule 支持创徏mock和宽杄反射参数匚w?/li>
  5. InjectModule 支持在一个对象中注入另一个对象?/li>
  6. SpringModule 支持加蝲spring的上下文配置Qƈ索和Spring Bean注入?/li>


]]>
Unitils开发指南(一Q?/title><link>http://www.aygfsteel.com/wangzhouyu/archive/2008/04/05/190908.html</link><dc:creator>小~咖啡?/dc:creator><author>小~咖啡?/author><pubDate>Sat, 05 Apr 2008 06:23:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangzhouyu/archive/2008/04/05/190908.html</guid><wfw:comment>http://www.aygfsteel.com/wangzhouyu/comments/190908.html</wfw:comment><comments>http://www.aygfsteel.com/wangzhouyu/archive/2008/04/05/190908.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangzhouyu/comments/commentRss/190908.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangzhouyu/services/trackbacks/190908.html</trackback:ping><description><![CDATA[<p>      单元试应该是简单和直观的,而现实中的项目大多都是采用多层方式的Q如EJB和hibernate的数据驱动层的中间g技术? <p>      unitils来源于一个尝试,是希望能以更务实的方式来看待单元测?..... <p>      q个指南会告诉你Q什么项目可以用unitils?q在q个<a >指导斚w?/a> 中你可以了解到测试的准侧和它的特炏V如果?zhn)想了解如何可以配|unitils Qƈ得以q速地启动Q请查看<a >cookbook</a> ? <ul> <li>unitils的断a <li>unitils的模? <li>数据库的试 <li>数据库的自动试 <li>hibernate的测? <li>jpa的测? <li>spring的测? <li>mock object的测? <li>今后的方?/li></ul> <p>      <strong>unitils的断a</strong></p> <p>      在开始这个指南之前我们先说明一下独立于unitils核心模块的断a。在下面的例子中Q不需要进行配|,unitils的jar包和依赖包放在你的classpath下,可以进行测试了?/p> <p>      通过反射q行断言</p> <p>      一个典型的单元试包含了结果值和期望值的比较Qunitils提供了断a的方法以帮助你进行该操作Q让我们看看实例2中对有着id、first name、last name属性的Usercȝ2个实例的比较</p><pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> User { <span style="color: #0000ff">private</span> <span style="color: #0000ff">long</span> id; <span style="color: #0000ff">private</span> String first; <span style="color: #0000ff">private</span> String last; <span style="color: #0000ff">public</span> User(<span style="color: #0000ff">long</span> id, String first, String last) { <span style="color: #0000ff">this</span>.id = id; <span style="color: #0000ff">this</span>.first = first; <span style="color: #0000ff">this</span>.last = last; } } User user1 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); User user2 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); assertEquals(user1, user2);</pre><pre> 你期望这个断a是成功的Q因两个实例含有相同的属性,但是q行的结果ƈ非如此,应ؓUsercdƈ没有覆写<br>equals()Ҏ(gu)Q所以assertEquals是对两个实例是否相等q行判断Quser1 == user2Q结果导致了比较的失败?/pre><pre> 假设你像如下代码一样实CequalsҎ(gu)</pre><pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">boolean</span> equals(Object <span style="color: #0000ff">object</span>) { <span style="color: #0000ff">if</span> (<span style="color: #0000ff">object</span> <span style="color: #0000ff">instanceof</span> User) { <span style="color: #0000ff">return</span> id == ((User) <span style="color: #0000ff">object</span>).id; } <span style="color: #0000ff">return</span> <span style="color: #0000ff">false</span>; }</pre> <p>       q在你的E序逻辑中是一个合乎逻辑的实玎ͼ当两个User实例拥有相同的id的时候,那么q两个实例就是相{的。然而这U方式在你的单元试中ƈ不合适,q不能通过id的相同来认ؓ两个user是相同的?/p><pre>User user1 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); User user2 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">Jane</span>", "<span style="color: #8b0000">Smith</span>"); assertEquals(user1, user2);</pre> <p>       q个断言会成功Q但qƈ不是你所期望的,因此不要使用assertEquals来对两个对象q行判定是否相等Q外覆类和java.lang.Stringc除外)。要xa他们相等Q一U方法就是断a每个属性相{?/p><pre>User user1 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); User user2 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); assertEquals(user1.getId(), user2.getId()); assertEquals(user1.getFirst(), user2.getFirst()); assertEquals(user1.getLast(), user2.getLast());</pre> <p>       unitils提供了一些方法来帮助你执行断a更加的简单,通过反射Q?em>ReflectionAssert.assertRefEquals</em>上面的代码重写如下:</p><pre>User user1 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); User user2 = <span style="color: #0000ff">new</span> User(1, "<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>"); assertRefEquals(user1, user2);</pre><pre> q个断言通过反射对两个实例中的每个属性都q行比较Q先是id、然后是first name、最后是last name?/pre><pre> 如果一个属性本w也是一个对象,那么会使用反射q行递归比较Q这同样适合与集合、map、和数组之间的比较,他们<br>的每个元素会通过反射q行比较。如果值是一个基本类型或者是一个外覆类Q那么将会?=q行值的比较Q因此下面的?br>a会取得成?/pre><pre>assertRefEquals(1, 1L); List<Double> myList = <span style="color: #0000ff">new</span> ArrayList<Double>(); myList.add(1.0); myList.add(2.0); assertRefEquals(Arrays.asList(1, 2), myList);</pre> <p>      <strong>宽松的断a</strong></p> <p><strong>     </strong>Z可维护性,q一Ҏ(gu)十分重要的,举例说明Q如果你要计一个帐L余额Q那你就没比较检查这个帐L名称。他只会增加复杂性,使之更难理解。如果你惌你的试代码更容易生存,更容易重构的话,那请保你断a的范围?/p> <p>      <em>宽松的顺?/em></p> <p><em>      </em>在比较集合和数组的时候你可能q不兛_他们中元素的序Q通过使用<i>ReflectionAssert.assertRefEquals</i>Ҏ(gu)q?i>ReflectionComparatorMode.LENIENT_ORDER</i>参数忽略元素的序?/p><pre>List<Integer> myList = Arrays.asList(3, 2, 1); assertRefEquals(Arrays.asList(1, 2, 3), myList, LENIENT_ORDER);</pre><pre> <em>无视默认</em></pre><pre><em> </em>W二U的从宽方式是?i>ReflectionComparatorMode.IGNORE_DEFAULTS</i>模式Q当q种模式被设|的时?java<br>的默认|如null?、false会不参与断aQ忽略)?/pre><pre> 举个例子Q如果你有一个Userc,该类有着first nameQlast nameQstreet{属性,但是你仅仅想对first name<br>和streetq行查而忽略其他的属性?/pre><pre>User actualUser = <span style="color: #0000ff">new</span> User("<span style="color: #8b0000">John</span>", "<span style="color: #8b0000">Doe</span>", <span style="color: #0000ff">new</span> Address("<span style="color: #8b0000">First street</span>", "<span style="color: #8b0000">12</span>", "<span style="color: #8b0000">Brussels</span>")); User expectedUser = <span style="color: #0000ff">new</span> User("<span style="color: #8b0000">John</span>", <span style="color: #0000ff">null</span>, <span style="color: #0000ff">new</span> Address("<span style="color: #8b0000">First street</span>", <span style="color: #0000ff">null</span>, <span style="color: #0000ff">null</span>)); assertRefEquals(expectedUser, actualUser, IGNORE_DEFAULTS);</pre> <p>      你所期望忽略的属性的对象必须攑֜断言左边Q如果放在右辚w么依然进行比较?/p><pre>assertRefEquals(<span style="color: #0000ff">null</span>, anyObject, IGNORE_DEFAULTS); <span style="color: #008000">// Succeeds</span> assertRefEquals(anyObject, <span style="color: #0000ff">null</span>, IGNORE_DEFAULTS); <span style="color: #008000">// Fails</span></pre> <p>      <em>宽松的日?/em></p> <p><em>      </em>W三U从宽处理是<em>ReflectionComparatorMode.LENIENT_DATESQ?/em>当两个日期都是|或者都是null的时候,实际的日期将会被忽略Q即断言为相{)?/p><pre>Date actualDate = <span style="color: #0000ff">new</span> Date(44444); Date expectedDate = <span style="color: #0000ff">new</span> Date(); assertRefEquals(expectedDate, actualDate, LENIENT_DATES);</pre> <p>      <em>assertLenEquals </em></p> <p><em>      ReflectionAssert</em>q提供了一U断aQ他提供宽松的顺序又提供无视的忽略?/p><pre>List<Integer> myList = Arrays.asList(3, 2, 1); assertLenEquals(Arrays.asList(1, 2, 3), myList); assertLenEquals(<span style="color: #0000ff">null</span>, "<span style="color: #8b0000">any</span>"); <span style="color: #008000">// Succeeds</span> assertLenEquals("<span style="color: #8b0000">any</span>", <span style="color: #0000ff">null</span>); <span style="color: #008000">// Fails</span></pre> <p>      <strong>属性断a</strong></p> <p><em>      assertLenEquals</em>?i>assertRefEquals</i>都是比较对象QReflectionAssert也提供方法对对象的属性进行比较。(依赖与ONGLQ?/p> <p>      一些属性比较的例子</p><pre>assertPropertyLenEquals("<span style="color: #8b0000">id</span>", 1, user); //断言user的id属性的值是1 assertPropertyLenEquals("<span style="color: #8b0000">address.street</span>", "<span style="color: #8b0000">First street</span>", user); //断言user的address的street属?/pre> <p>      在这个方式中你期望的值和判定的对象也可以使用集合</p><pre>assertPropertyLenEquals("<span style="color: #8b0000">id</span>", Arrays.asList(1, 2, 3), users); assertPropertyLenEquals("<span style="color: #8b0000">address.street</span>", Arrays.asList("<span style="color: #8b0000">First street</span>", <br> "<span style="color: #8b0000">Second street</span>", "<span style="color: #8b0000">Third street</span>"), users);</pre><img src ="http://www.aygfsteel.com/wangzhouyu/aggbug/190908.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangzhouyu/" target="_blank">小~咖啡?/a> 2008-04-05 14:23 <a href="http://www.aygfsteel.com/wangzhouyu/archive/2008/04/05/190908.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>单元试的十二信?/title><link>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/30/114712.html</link><dc:creator>小~咖啡?/dc:creator><author>小~咖啡?/author><pubDate>Mon, 30 Apr 2007 01:59:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/30/114712.html</guid><wfw:comment>http://www.aygfsteel.com/wangzhouyu/comments/114712.html</wfw:comment><comments>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/30/114712.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangzhouyu/comments/commentRss/114712.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangzhouyu/services/trackbacks/114712.html</trackback:ping><description><![CDATA[ <blockquote> <ol> <li>写代码,׃定要写测?/li> <li>不要受单元测试的教条所?/li> <li>怿单元试会带来的成?/li> <li>l一考虑~码和测?/li> <li>试比单元代码重?/li> <li>试的最x机是代码刚写完之?/li> <li>试不会白费</li> <li>当天有瑕늚试也比后补的完测试好</li> <li>不好的测试也比没有测试强</li> <li>试有时可以验证意图</li> <li>只有?c)不用工?/li> <li>用好的去试不好?/li> </ol> <p>引至QInfo中文|站<a >http://www.infoq.com/cn/news/2007/04/savoia-tao-of-testing</a></p> </blockquote> <img src ="http://www.aygfsteel.com/wangzhouyu/aggbug/114712.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangzhouyu/" target="_blank">小~咖啡?/a> 2007-04-30 09:59 <a href="http://www.aygfsteel.com/wangzhouyu/archive/2007/04/30/114712.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tomcat的URIEncodinghttp://www.aygfsteel.com/wangzhouyu/archive/2007/04/26/113705.html小~咖啡?/dc:creator>小~咖啡?/author>Thu, 26 Apr 2007 02:33:00 GMThttp://www.aygfsteel.com/wangzhouyu/archive/2007/04/26/113705.htmlhttp://www.aygfsteel.com/wangzhouyu/comments/113705.htmlhttp://www.aygfsteel.com/wangzhouyu/archive/2007/04/26/113705.html#Feedback0http://www.aygfsteel.com/wangzhouyu/comments/commentRss/113705.htmlhttp://www.aygfsteel.com/wangzhouyu/services/trackbacks/113705.html實際運用 Tomcat 5.0.19Q我們了解在不修?Tomcat 原始的狀況下Q用者透過 Form submit 的資料將一律以 ISO8859-1 處理Q程式設a師必須自行字串將轉換?Big5(J體中文) or GB2312/GBK(體中文)Q我們在應用E式中,所有的 request.getParameter("xx"); 作了 toBig5String() 的處理,理論上,所有的中文問題應該不會出現才對Q結果,還是發現某些狀況下Q中文還是變成亂|

E過分析整理Q我們發珑֕出?QueryString 的解析,以前?Tomcat 4.x 時代Q無?SUBMIT 時採?GET or POSTQTomcat server ?parameters 的處理都採用相同的編|但在 Tomcat 5.x 版,不知何故Q卻?QueryString 的解析獨立出來,目前QForm ?Method 採用 GET 及直接將參數寫在 URL 上的中文Q上傛_ Tomcat 時,無論如何轉碼Q都會變成亂|那怕你事先作過 URLEncode 也一樣?br/>
E站上,有h針對這個問,所有中文改採用 base64 R碼Q到?server 上,E式自行土 base64 decode 回來Q確保中文不會發生問。這樣作法當然可以解決這個問,但是所有網頁變成限定要採用 POSTQ且E式a計師要隨時分清楚,那個參數是採用 GET 上傳Q那個參數是採用 POST 上傳Q然後再針對不同的方式採用不同的解析Q這樣的程式一點兒UL性都沒有Q更別提跨^台、跨國際語言了?br/>
研究 Tomcat 的文件及原始|我們找C問題所在及解決的方法,只有按著以下的作法,才能?Form submit 的資料完全按?ISO8859-1 的編|當然Q若是全照著 Tomcat 的文件說明去作,肯定還是不行Q你還是得加上這個參數到 server.xml 中才行?br/>
解決Ҏ(gu)

請先研究 $TOMCAT_HOME/webapps/tomcat-docs/config/http.html 這個說明檔Q擷錄重點如下:
URIEncodingQThis specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.

useBodyEncodingForURIQThis specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding. This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitely set using Request.setCharacterEncoding method was also used for the parameters from the URL. The default value is false.

上述二?Tomcat 參數Q是a定?server.xml 中的 http <Connector /> 區塊,要解?QueryString 中文變成亂碼的問,你必須至設定這二個參數其中之一?br/>URIEncoding 請設定為 URIEncoding="ISO-8859-1" 指定?"ISO-8859-1" R碼Q讓 QueryString 的字元編D post body 相同?br/>useBodyEncodingForURI 這是用來相容 Tomcat 4.x 版的Q設定的值是 "true" or "false"Q意思是?"要不要讓 QueryString ?POST BODY 採用相同的字元編??"Q若是設?trueQ那也可達到 "ISO-8859-1" R碼的需求?br/>Q採?URIEncoding 的設定,畢竟 useBodyEncodingForURI 的作法是Z相容 Tomcat 4.X。不過若照原文的說明Q理論上這二個參敔R不設QTomcat 也該採用 "ISO-8859-1" 的編|那為什麼還是會有問呢 ? 我們由 Tomcat Source Code 來看清楚了?br/>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// 這一D늢?Tomcat 用來?QueryString 的程式,
// ?org.apache.tomcat.util.http.Parameters 這?class 裡?private String urlDecode(ByteChunk bc, String enc)
  throws IOException {
  if( urlDec==null ) {
     urlDec=new UDecoder(); 
  }
  urlDec.convert(bc);
  String result = null;
  if (enc != null) {
    bc.setEncoding(enc);
    result = bc.toString();
  } 
  else {
    CharChunk cc = tmpNameC;
    cc.allocate(bc.getLength(), -1);
    // Default encoding: fast conversion
    byte[] bbuf = bc.getBuffer();
    char[] cbuf = cc.getBuffer();
    int start = bc.getStart();
    for (int i = 0; i < bc.getLength(); i++) {
      cbuf[i] = (char) (bbuf[i + start] & 0xff);
    }
    cc.setChars(cbuf, 0, bc.getLength());
    result = cc.toString();
    cc.recycle();
  }
  return result;
}

請特別注意紅色區塊,?Tomcat 發現 QueryString 並沒有設?encode 時,並非像文件中所說預a採?ISO-8859-1 的編|而是用一D?fast conversion 來處理,才會造成中文問題Q所以,還是必須?Server.xml 中,加上 URLEncoding 的參數設定才行哦?br/>
Connector 的設定範例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<Connector
debug="0"
acceptCount="100"
connectionTimeout="20000"
disableUploadTimeout="true"
port="80"
redirectPort="8443"
enableLookups="false"
minSpareThreads="25"
maxSpareThreads="75"
maxThreads="150"
maxPostSize="0"
URIEncoding="ISO-8859-1"
>
</Connector>

文章来至Q?a >http://www.javaworld.com.tw/jute/post/view?bid=9&id=44042&sty=1&tpg=1&age=0

]]>
IntelliJ IDEA 7.0M1发布?/title><link>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/12/110057.html</link><dc:creator>小~咖啡?/dc:creator><author>小~咖啡?/author><pubDate>Thu, 12 Apr 2007 01:07:00 GMT</pubDate><guid>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/12/110057.html</guid><wfw:comment>http://www.aygfsteel.com/wangzhouyu/comments/110057.html</wfw:comment><comments>http://www.aygfsteel.com/wangzhouyu/archive/2007/04/12/110057.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wangzhouyu/comments/commentRss/110057.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wangzhouyu/services/trackbacks/110057.html</trackback:ping><description><![CDATA[ <p>l对的最强的java ide?.0M1已经ZQ快去试试把Q?br/><a >http://www.jetbrains.com/idea/nextversion/</a><br/></p> <img src ="http://www.aygfsteel.com/wangzhouyu/aggbug/110057.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wangzhouyu/" target="_blank">小~咖啡?/a> 2007-04-12 09:07 <a href="http://www.aygfsteel.com/wangzhouyu/archive/2007/04/12/110057.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">̽</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">¡</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">̨</a>| <a href="http://" target="_blank">˫</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">żҴ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ī</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">֣</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ӣ</a>| <a href="http://" target="_blank">᯹</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank">ϻ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͼ</a>| <a href="http://" target="_blank">Ͷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ߴ</a>| <a href="http://" target="_blank">ĺ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>