• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

dbUnit对mssqlserver自增长主键的处理

发布: 2007-7-01 18:47 | 作者: admin | 来源: | 查看: 68次 | 进入软件测试论坛讨论

领测软件测试网  

package com.sourceware.test;

/*******************************************************************************
 * Copyright (c) 2000, 2005 ZhongKe Corporation and others.
 * All rights reserved. This program and the accompanying 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>标题: 消息服务</p>
 *
 * <p>描述: 消息服务平台</p>
 *
 * <p>版权: 宁波中科信息产业有限公司 Copyright (c) 2004</p>
 *
 * <p>公司: 宁波中科信息产业有限公司</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;
  }

}


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网