JIRA 4.2.4数据导入到Mantis1.2.15测试用例(初步)

JIRA 4.2.4数据导入到Mantis测试用例(初步):

package com.capitalbio.soft.test.bug;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

public class JiraToMantisTest {
	private static String driverName = "com.mysql.jdbc.Driver";
	private static String url_jira = "jdbc:mysql://192.168.6.250:3306/jira?useUnicode=true&characterEncoding=utf-8";
	private static String url_mantis = "jdbc:mysql://192.168.6.250:3306/mantis_jira?useUnicode=true&characterEncoding=utf-8";
	private static String user = "root";
	private static String password = "root";
	/*
	static {
		try {
			Class.forName(driverName);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}  
	*/
	public static BasicDataSource getDataSource(String url) {
		BasicDataSource dataSource = new BasicDataSource();
		
		dataSource.setDriverClassName(driverName);
		dataSource.setUrl(url);
		dataSource.setUsername(user);
		dataSource.setPassword(password);
		
		return dataSource;
	}
	
	@Test public void testJiraToMantis() {
		final JdbcTemplate jiraJdbcTemplate = new JdbcTemplate(getDataSource(url_jira));
		final JdbcTemplate mantisJdbcTemplate = new JdbcTemplate(getDataSource(url_mantis));
		String sql = "select * from jiraissue ";
		final String insert_mantis_bug_table_sql = "INSERT INTO mantis_bug_table ( project_id, reporter_id, handler_id, duplicate_id, priority, severity, reproducibility, STATUS, resolution, projection, eta, bug_text_id, os, os_build, platform, VERSION, fixed_in_version, build, profile_id, view_state, summary, sponsorship_total, sticky, target_version, category_id, date_submitted, due_date, last_updated ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
		final String insert_mantis_bug_text_table_sql = "INSERT INTO mantis_bug_text_table (description, steps_to_reproduce, additional_information) VALUES (?, '', '')";
		final AtomicInteger total = new AtomicInteger(0);
		jiraJdbcTemplate.query(sql, new RowMapper<Object>(){
			@Override public Object mapRow(ResultSet rs, int idx) throws SQLException {
				final String description = null!=rs.getString("description") ? rs.getString("description") : "";
				KeyHolder keyHolder = new GeneratedKeyHolder();
				mantisJdbcTemplate.update(new PreparedStatementCreator() {
					@Override public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
						PreparedStatement ps = conn.prepareStatement(insert_mantis_bug_text_table_sql, Statement.RETURN_GENERATED_KEYS);
						ps.setString(1, description);
						return ps;
					}
				},keyHolder);
				Integer bug_text_id = keyHolder.getKey().intValue();
				/*.execute(String.format(insert_mantis_bug_text_table_sql,description), new PreparedStatementCallback<Integer>() {
					@Override public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
						ps.executeupdate
						ResultSet rs = ps.getGeneratedKeys();
						if(rs.next()) return rs.getInt(1);
						return null;
					}
				});*/
				
				BigDecimal proj_id = rs.getBigDecimal("PROJECT");
				int project_id = (10000==proj_id.intValue()) ? 1:2;
				Integer reporter_id = StringUtils.isNotBlank(rs.getString("reporter")) ? mantisJdbcTemplate.queryForInt("SELECT id FROM mantis_user_table WHERE username=?", rs.getString("reporter")) : null;
				Integer handler_id = StringUtils.isNotBlank(rs.getString("assignee")) ? mantisJdbcTemplate.queryForInt("SELECT id FROM mantis_user_table WHERE username=?", rs.getString("assignee")) : null;
				int duplicate_id = 0;
				int priority = 30;
				int severity = 50;
				int reproducibility = 10;
				int status = 90;
				int resolution = 20;
				int projection = 10;
				int eta = 10;
//				bug_text_id;
				String os = "";
				String os_build = "";
				String platform = "";
				String version = "";
				String fixed_in_version = "";
				String build = "";
				int profile_id = 0;
				int view_state = 10;
				String summary = rs.getString("summary");
				int sponsorship_total = 0;
				int sticky = 0;
				String target_version = "";
				int category_id = 1;
				String dateSubmitted = Long.toString(rs.getDate("CREATED").getTime());
				int date_submitted = Integer.parseInt(dateSubmitted.substring(0, dateSubmitted.length()-3)); //1379820334;
				int due_date = 1;
				String lastUpdated = Long.toString(rs.getDate("UPDATED").getTime());
				int last_updated = Integer.parseInt(lastUpdated.substring(0, lastUpdated.length()-3));//1379820334;
				
				total.addAndGet(mantisJdbcTemplate.update(insert_mantis_bug_table_sql, project_id, reporter_id, handler_id, duplicate_id, priority, severity, reproducibility, status, resolution, projection, eta, bug_text_id, os, os_build, platform, version, fixed_in_version, build, profile_id, view_state, summary, sponsorship_total, sticky, target_version, category_id, date_submitted, due_date, last_updated));
				return null;
			}
		});
		System.out.println("----------------" + total.get());
	}
	
	@Test public void testDate() {
//		1384926801922 //		1384926882
		String ret = Long.toString(new Date().getTime());
		System.out.println(ret.substring(0, ret.length()-3));
	}

}

 

你可能感兴趣的:(jira)