Forums: Open Discussion (Thread #19186)

terasoluna-spring-thin-blankでのJUitテストについて (2008-07-01 13:12 by Anonymous #37404)

初めて投稿させていただきます。

terasolnaのweb版を使用して開発を行っています。
そこて単体テストを実施しようとしたのですが、
SQL取得の試験のとこでQueryDAOを取得しようとしても
nullが返ってきてしまいテストが進まない状態でいます。
このときにJUnitで何か初期処理としてsetUp()メソッドに何か記述しないといけないのでしょうか。

よろしくお願いします。

Reply to #37404×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: terasoluna-spring-thin-blankでのJUitテストについて (2009-01-14 21:17 by Anonymous #41202)

Springを用いて、xmlでセットされた値を取得します。

FileSystemResouse("web-inf/appli××")
Reply to #37404

Reply to #41202×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: terasoluna-spring-thin-blankでのJUitテストについて (2009-01-22 10:34 by kimumasa #41385)

以下のようなテスト対象であれば、
一例として以下のようにも行うことが出来ます。

[テスト対象クラス]
※コンパイル済みかつ、動作する事が前提です。
package jp.terasoluna.sample.blogic;
import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.service.thin.BLogic;
import jp.terasoluna.fw.service.thin.BLogicResult;

public class SampleBLogic implements BLogic {

private QueryDAO queryDAO;

public void setQueryDAO(QueryDAO queryDAO) {
this.queryDAO = queryDAO;
}

public BLogicResult execute(Object params) {
BLogicResult result = new BLogicResult();

System.out.println(queryDAO.executeForObject("test", null, String.class));
return result;
}

}

【作業①】
terasoluna-lib-web_2.0.1.0.zipに包含される
terasoluna-server4jweb-projects_2.0.1.0.zipを解凍し中にある
===
junit-3.8.2.jar
junit-addons-1.4.jar
mockrunner.jar
spring-test.jar
terasoluna-utlib-spring.jar
terasoluna-utlib.jar
===
をクラスパス上に配置します。

【作業②】
sqlMapConfig.xml、dao-test.xml、test.propertiesを作成し、
クラスパス上の直下においてください。
※sqlMapConfig.xmlはご利用のものをコピーしてください。
※配置場所はテストケースのソースが置いてあるフォルダ直下が適当だと思います。

[dao-test.xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
- データアクセス処理テスト用の定義ファイル。
-->
<beans>

<!-- iBATIS データベース層のためのSQlMapの設定 -->

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="sqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>

<!-- ===================== DAO定義: IBATIS実装 ===================== -->
<!-- 照会系のDAO -->
<bean id="queryDAO"
class="jp.terasoluna.fw.dao.ibatis.QueryDAOiBatisImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

<!-- 更新系のDAO -->
<bean id="updateDAO"
class="jp.terasoluna.fw.dao.ibatis.UpdateDAOiBatisImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

<!-- ストアドプロシジャ用のDAO -->
<bean id="spDAO"
class="jp.terasoluna.fw.dao.ibatis.StoredProcedureDAOiBatisImpl">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

<!-- ===================== Oracle固有定義 ===================== -->
<!-- シーケンス実装クラスの定義 -->
<bean id="dbSequence"
class="jp.terasoluna.utlib.spring.SpringOracleDBSequence">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>

</beans>

[test.properties]
# JDBC用プロパティの設定。
# terasoluna-utlib-spring.jar内の
# "dataAccessContext-local.xml"ファイル内のPropertyPlaceholderConfigurer
# にてプレースホルダとして使用されている。
# ドライバ名等はご利用の環境に編集してください。
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:SID
jdbc.username=id
jdbc.password=password


【作業③】
以下のようなテストコードを作成します。
package jp.terasoluna.sample.blogic;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.service.thin.BLogic;
import jp.terasoluna.utlib.spring.DaoTestCase;
import junit.framework.TestCase;

public class SampleBLogicTest extends DaoTestCase {

/**
* 利用するDAOクラス
*/
private QueryDAO queryDAO = null;

public void testExecute01() throws Exception {

SampleBLogic blogic = new SampleBLogic();

blogic.setQueryDAO(queryDAO);
blogic.execute(null);

}

/**
* QueryDAOを設定する
*/
public void setQueryDAO(QueryDAO param){
this.queryDAO = param;
}


@Override
protected String[] doGetConfigLocations() {
return new String[] {"/dao-test.xml"};
}

// ★★★★以下はテーブルの初期化が必要であれば実装してください。★★★★
//
// private static final String tableNames[]={
// "TABLE_NAME"
// };
//
@Override
protected void cleanUpData() throws Exception {
// //テーブルデータの削除
// for(int i=0;i< tableNames.length;i++){
// super.deleteAllData(tableNames[i]);
// }
}


@Override
protected void setUpData() throws Exception {
// //テーブルデータの初期化
// for(int i=0;i< tableNames.length;i++){
// super.deleteAllData(tableNames[i]);
// }
//
// //固定テーブルCUSTOMERのテストデータの設定
// String[][] data = new String[][]{
// {"COL_1","COL_2"},
// {"00000001","山田太郎"},
// {"00000002","山田次郎"},
// {"00000003","山田三郎"}
// };
// super.insertData("TABLE_NAME",data);
}
}
Reply to #37404

Reply to #41385×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: terasoluna-spring-thin-blankでのJUitテストについて (2014-01-01 08:32 by roz #71175)

設定をしたところ、以下と同じようなメッセージでJUnitが異常終了しました。
http://sourceforge.jp/projects/terasoluna/forums/13381/23630/45448/

テストソース内に、「jp.terasoluna.utlib.spring」パッケージを作成し、
terasoluna-utlib-spring-1.1.0.jarをzipにして解凍したDaoTestCase.xmlの
「destroy-method="close"」を削除したところ上手くいきました。

JUnit異常終了ログ:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [jp/terasoluna/utlib/spring/DaoTestCase.xml]: Invalid destruction signature; nested exception is org.springframework.beans.factory.support.BeanDefinitionValidationException: Couldn't find a destroy method named 'close' on bean with name 'dataSource'

ダウンロードプロジェクト:terasoluna-server4jweb-all_2.0.5.0

助かりました。ありがとうございました。

Reply to #41385

Reply to #71175×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login