您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源單元測(cè)試工具 > DBunit
dbUnit對(duì)mssqlserver自增長(zhǎng)主鍵的處理
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/1/21 15:07:00 ] 推薦標(biāo)簽:

package com.sourceware.test;

/*******************************************************************************
 * Copyright (c) 2000, 2005 ZhongKe Corporation and others.
 * All rights reserved. This program and the aclearcase/" target="_blank" >ccompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.source-ware.com/
 *
 * Contributors:
 *    ZhongKe Corporation - initial API and implementation
 *******************************************************************************/

import java.io.InputStream;
import java.sql.Connection;

import org.dbunit.DatabaseTestCase;
import org.dbunit.database.DatabaseConfig;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.operation.DatabaseOperation;

import com.sourceware.sms.platform.dao.SMSDAO;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.ApplicationContext;
import javax.sql.DataSource;

/**
 *
 * <p>標(biāo)題: 消息服務(wù)</p>
 *
 * <p>描述: 消息服務(wù)平臺(tái)</p>
 *
 * <p>版權(quán): 寧波中科信息產(chǎn)業(yè)有限公司 Copyright (c) 2004</p>
 *
 * <p>公司: 寧波中科信息產(chǎn)業(yè)有限公司</p>
 *
 * @author 吳鋒彬(woowind@sina.com)
 * @version 1.0
 */
public class BaseDatabaseTestCase
    extends DatabaseTestCase {
  static ApplicationContext appContext;
  private final static String batchID =
      "http://www.dbunit.org/features/batchedStatements";
  static DataSource ds;
 
  static {
    appContext =
        new ClassPathXmlApplicationContext("xml/sms-platform-context.xml");
     ds = (DataSource) appContext.getBean("dataSource");


  }


  protected void setUp() throws Exception {
    super.setUp();
  }

  protected void tearDown() throws Exception {
    super.tearDown();
    this.getConnection().close();
  }

  /* (non-Javadoc)
   * @see org.dbunit.DatabaseTestCase#getConnection()
   */
  protected IDatabaseConnection getConnection() throws Exception {

    IDatabaseConnection iDataBaseConnection = new DatabaseConnection(ds.
        getConnection());
    DatabaseConfig config = iDataBaseConnection.getConfig();

    //Enable Batched statements
    if (!config.getFeature(batchID)) {
      config.setFeature(batchID, true);
    }

    return iDataBaseConnection;

  }

  /* (non-Javadoc)
   * @see org.dbunit.DatabaseTestCase#getDataSet()
   */
  protected IDataSet getDataSet() throws Exception {
    InputStream is = this.getClass().getClassLoader().getResourceAsStream(
        "dataset/fmsDomain.xml");
    return new FlatXmlDataSet(is);
  }

  protected DatabaseOperation getSetUpOperation() throws Exception {
    return org.dbunit.ext.mssql.InsertIdentityOperation.INSERT;

  }

  protected DatabaseOperation getTearDownOperation() throws Exception {
    return  org.dbunit.ext.mssql.InsertIdentityOperation.CLEAN_INSERT;
  }

}

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd