CommonIT.java 11.6 KB
Newer Older
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 30 31 32 33 34 35 36 37
package pwc.taxtech.atms;

import java.io.InputStreamReader;
import java.io.Reader;
import java.sql.Connection;

import org.apache.ibatis.jdbc.ScriptRunner;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.runner.RunWith;
import org.nutz.lang.Lang;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.test.context.web.WebAppConfiguration;
import pwc.taxtech.atms.dao.*;
import pwc.taxtech.atms.entity.AreaExample;
import pwc.taxtech.atms.entity.AreaRegionExample;
import pwc.taxtech.atms.entity.CustomerExample;
import pwc.taxtech.atms.entity.EnterpriseAccountExample;
import pwc.taxtech.atms.entity.EnterpriseAccountSetExample;
import pwc.taxtech.atms.entity.EnterpriseAccountSetOrgExample;
import pwc.taxtech.atms.entity.IndustryExample;
import pwc.taxtech.atms.entity.MenuExample;
import pwc.taxtech.atms.entity.OperationLogBasicDataExample;
import pwc.taxtech.atms.entity.OperationLogEnterPriseExample;
import pwc.taxtech.atms.entity.OrganizationExample;
import pwc.taxtech.atms.entity.ProjectClientExample;
import pwc.taxtech.atms.entity.RegionExample;
import pwc.taxtech.atms.entity.ServiceTypeExample;
import pwc.taxtech.atms.entity.StandardAccountExample;
import pwc.taxtech.atms.entity.TemplateGroupExample;
import pwc.taxtech.atms.service.impl.DistributedIdService;
38
import pwc.taxtech.atms.vat.dao.CashFlowMapper;
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
import pwc.taxtech.atms.vat.dao.PeriodTemplateMapper;

@WebAppConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public abstract class CommonIT {

    private static final Logger logger = LoggerFactory.getLogger(CommonIT.class);

    static {
        System.setProperty("atms_env_id", "test");
    }

    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    @Autowired
    protected ObjectMapper objectMapper;

    @Autowired
    protected AreaMapper areaMapper;
    @Autowired
    protected AreaRegionMapper areaRegionMapper;
    @Autowired
    protected RegionMapper regionMapper;
    @Autowired
    protected EnterpriseAccountSetMapper enterpriseAccountSetMapper;
    @Autowired
    protected EnterpriseAccountMapper enterpriseAccountMapper;
    @Autowired
    protected StandardAccountMapper standardAccountMapper;
    @Autowired
    protected EnterpriseAccountSetOrgMapper enterpriseAccountSetOrgMapper;
    @Autowired
    protected AccountMappingMapper accountMappingMapper;
    @Autowired
    protected OperationLogBasicDataMapper operationLogBasicDataMapper;
    @Autowired
    protected OperationLogEnterPriseMapper operationLogEnterpriseMapper;
    @Autowired
    protected OrganizationMapper organizationMapper;
    @Autowired
    protected CustomerMapper customerMapper;
    @Autowired
    protected UserMapper userMapper;
    @Autowired
    protected MenuMapper menuMapper;
    @Autowired
    protected BusinessUnitMapper businessUnitMapper;
    @Autowired
    protected UserRoleMapper userRoleMapper;
    @Autowired
    protected RolePermissionMapper rolePermissionMapper;
    @Autowired
    protected PermissionMapper permissionMapper;
    @Autowired
    protected MailQueueMapper mailQueueMapper;
    @Autowired
    protected TemplateGroupMapper templateGroupMapper;
    @Autowired
    protected TemplateMapper templateMapper;
    @Autowired
    protected ServiceTypeMapper serviceTypeMapper;
    @Autowired
    protected ProjectClientMapper projectClientMapper;
    @Autowired
    protected RoleCategoryMapper roleCategoryMapper;
    @Autowired
    protected RoleMapper roleMapper;
    @Autowired
    protected UserDimensionValueMapper userDimensionValueMapper;
    @Autowired
    protected UserDimensionValueOrgMapper userDimensionValueOrgMapper;
    @Autowired
    protected UserDimensionValueRoleMapper userDimensionValueRoleMapper;
    @Autowired
    protected UserOrganizationMapper userOrganizationMapper;
    @Autowired
    protected UserOrganizationRoleMapper userOrganizationRoleMapper;
    @Autowired
    protected DimensionValueOrgMapper dimensionValueOrgMapper;
    @Autowired
    protected DimensionMapper dimensionMapper;
    @Autowired
    protected DimensionValueMapper dimensionValueMapper;
    @Autowired
    protected IndustryMapper industryMapper;
    @Autowired
    protected OrganizationStructureMapper organizationStructureMapper;
    @Autowired
    protected CacheMapper cacheMapper;
    @Autowired
    protected StatisticAttributeDimensionMapper statisticAttributeDimensionMapper;
    @Autowired
    protected StatisticAttributeMapper statisticAttributeMapper;
    @Autowired
    protected OperationLogOrganizationMapper operationLogOrganizationMapper;
    @Autowired
    protected OperationLogRoleMapper operationLogRoleMapper;
    @Autowired
    protected DictionaryMapper dictionaryMapper;
    @Autowired
    protected OperationLogUserMapper operationLogUserMapper;
    @Autowired
    protected OrganizationServiceTemplateGroupMapper organizationServiceTemplateGroupMapper;
    @Autowired
    protected DistributedIdService distributedIdService;
    @Autowired
    protected CellTemplateMapper cellTemplateMapper;
    @Autowired
    protected CellTemplateConfigMapper cellTemplateConfigMapper;
    @Autowired
    protected  TaxPayerReportRuleMapper taxPayerReportRuleMapper;
    @Autowired
    protected  TaxRuleSettingOrganizationMapper taxRuleSettingOrganizationMapper;
    @Autowired
    protected  TaxRuleSettingMapper taxRuleSettingMapper;
    @Autowired
    protected PeriodTemplateMapper periodTemplateMapper;
157 158
    @Autowired
    protected CashFlowMapper cashFlowMapper;
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324

    protected void execSqlFile(String sqlFilePath) {

        Connection conn = null;
        ScriptRunner runner = null;
        Reader reader = null;
        try {
            conn = sqlSessionFactory.openSession().getConnection();
            runner = new ScriptRunner(conn);
            runner.setAutoCommit(true);
            runner.setFullLineDelimiter(true);
            runner.setDelimiter("GO");
            runner.setSendFullScript(false);
            // runner.setStopOnError(false);
            runner.setStopOnError(true);
            runner.setLogWriter(null);

            reader = new InputStreamReader(ClassLoader.getSystemResourceAsStream(sqlFilePath), "utf-8");
            runner.runScript(reader);

        } catch (Exception e) {
            logger.error("Error executing sql file " + sqlFilePath, e);
            throw Lang.wrapThrow(e);
        } finally {
            try {
                if (conn != null) {
                    runner.closeConnection();
                    conn.close();
                }
                if (reader != null) {
                    reader.close();
                }
            } catch (Exception e) {
                if (conn != null) {
                    conn = null;
                }
                if (reader != null) {
                    reader = null;
                }
            }
        }

    }

    protected void cleanUpAllTables() {
        cleanUpAreaTable();
        cleanUpAreaRegionTable();
        cleanUpRegionTable();
        cleanUpEnterpriseAccountSetTable();
        cleanUpEnterpriseAccountTable();
        cleanUpStandardAccountTable();
        cleanUpEnterpriseAccountSetOrgTable();
        accountMappingMapper.deleteByExample(null);
        cleanUpOperationLogBasicDataTable();
        cleanUpOperationLogEnterPriseTable();
        cleanUpOrganizationTable();
        userMapper.deleteByExample(null);
        cleanUpMenuTable();
        businessUnitMapper.deleteByExample(null);
        userRoleMapper.deleteByExample(null);
        rolePermissionMapper.deleteByExample(null);
        permissionMapper.deleteByExample(null);
        mailQueueMapper.deleteByExample(null);
        cleanUpTemplateGroupTable();
        cleanUpServiceTypeTable();
        cleanUpProjectClientTable();
        cleanUpIndustryTable();
        roleCategoryMapper.deleteByExample(null);
        roleMapper.deleteByExample(null);
        userDimensionValueMapper.deleteByExample(null);
        userDimensionValueOrgMapper.deleteByExample(null);
        userDimensionValueRoleMapper.deleteByExample(null);
        userOrganizationMapper.deleteByExample(null);
        userOrganizationRoleMapper.deleteByExample(null);
        dimensionValueOrgMapper.deleteByExample(null);
        organizationStructureMapper.deleteByExample(null);

        dimensionMapper.deleteByExample(null);
        dimensionValueMapper.deleteByExample(null);
        statisticAttributeMapper.deleteByExample(null);
        statisticAttributeDimensionMapper.deleteByExample(null);
        operationLogOrganizationMapper.deleteByExample(null);
        operationLogRoleMapper.deleteByExample(null);
        operationLogUserMapper.deleteByExample(null);
        organizationServiceTemplateGroupMapper.deleteByExample(null);
    }

    private void cleanUpProjectClientTable() {
        ProjectClientExample example = new ProjectClientExample();
        projectClientMapper.deleteByExample(example);
    }

    private void cleanUpIndustryTable() {
        IndustryExample example = new IndustryExample();
        industryMapper.deleteByExample(example);
    }

    private void cleanUpTemplateGroupTable() {
        TemplateGroupExample example = new TemplateGroupExample();
        templateGroupMapper.deleteByExample(example);
    }

    private void cleanUpServiceTypeTable() {
        ServiceTypeExample example = new ServiceTypeExample();
        serviceTypeMapper.deleteByExample(example);
    }

    protected void cleanUpAreaTable() {
        AreaExample example = new AreaExample();
        areaMapper.deleteByExample(example);
    }

    protected void cleanUpAreaRegionTable() {
        AreaRegionExample example = new AreaRegionExample();
        areaRegionMapper.deleteByExample(example);
    }

    protected void cleanUpRegionTable() {
        RegionExample example = new RegionExample();
        regionMapper.deleteByExample(example);
    }

    protected void cleanUpOperationLogBasicDataTable() {
        OperationLogBasicDataExample example = new OperationLogBasicDataExample();
        operationLogBasicDataMapper.deleteByExample(example);
    }

    protected void cleanUpOperationLogEnterPriseTable() {
        OperationLogEnterPriseExample example = new OperationLogEnterPriseExample();
        operationLogEnterpriseMapper.deleteByExample(example);
    }

    protected void cleanUpEnterpriseAccountSetTable() {
        EnterpriseAccountSetExample example = new EnterpriseAccountSetExample();
        enterpriseAccountSetMapper.deleteByExample(example);
    }

    protected void cleanUpEnterpriseAccountTable() {
        EnterpriseAccountExample example = new EnterpriseAccountExample();
        enterpriseAccountMapper.deleteByExample(example);
    }

    protected void cleanUpStandardAccountTable() {
        StandardAccountExample example = new StandardAccountExample();
        standardAccountMapper.deleteByExample(example);
    }

    protected void cleanUpEnterpriseAccountSetOrgTable() {
        EnterpriseAccountSetOrgExample example = new EnterpriseAccountSetOrgExample();
        enterpriseAccountSetOrgMapper.deleteByExample(example);
    }

    protected void cleanUpOrganizationTable() {
        OrganizationExample example = new OrganizationExample();
        organizationMapper.deleteByExample(example);
    }

    protected void cleanUpCustomerTable() {
        CustomerExample example = new CustomerExample();
        customerMapper.deleteByExample(example);
    }

    protected void cleanUpMenuTable() {
        MenuExample example = new MenuExample();
        menuMapper.deleteByExample(example);
    }
sherlock's avatar
sherlock committed
325 326


327
}