/** * */ package com.dtsz.model.service.test; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import junit.framework.TestCase; import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner; import net.sourceforge.groboutils.junit.v1.TestRunnable; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.dtsz.model.entity.authenticator.User; import com.dtsz.model.entity.report.common.InvokeSource; import com.dtsz.model.service.authenticator.UserManager; import com.dtsz.model.service.authenticator.UserService; import com.dtsz.model.service.exception.BaseAppException; import com.dtsz.model.util.BeanUtil2; import com.dtsz.model.util.Constant; import com.dtsz.model.util.Encryption; import com.dtsz.view.util.SpringContextListener; import com.dtsz.view.vo.authenticator.UserVO; /** * 模拟数据上报,这里的初始化数据根据插件端传入数据组合来的,当前只有根据报表期生成初始化数据 * * @author xiaoli * */ public class CreateMultiTaskReportTest3 extends TestCase { private UserManager userManager; private UserService userService; @Override protected void setUp() throws Exception { super.setUp(); String[] paths = { "classpath:applicationContext.xml" }; ApplicationContext ctx = new ClassPathXmlApplicationContext(paths); SpringContextListener.setApplicationContext(ctx); // ############模拟servlet容器启动,手动更改配置文件路径 Constant.CURRENT_PROJECT_PATH = "src/"; // ############直接容器中获取bean userManager = (UserManager) ctx.getBean("userManager"); userService = (UserService) ctx.getBean("userService"); } @Override protected void tearDown() throws Exception { super.tearDown(); } @Test public void test(){ // ###########自动生成报表期串集合 List<String> bbqs = new ArrayList<String>(); UnitTestUtils.imitateCreateMultiBbq(bbqs, 2, "2048", "5"); // 创建线程 TestRunnable[] tr = new TestRunnable[bbqs.size()]; int processCount = 0; // ##########对这些数据进行填报 for (String bbq : bbqs) { // 模拟上报数据 String reportMap = "{taskID:\"402880ee425a92f501425aa75ad50002\",bbq_:\"" + bbq + "\"" + ",bbhid:\"402855b942099b1b014209b1177e03f5\",approvalFlag:2,reportFlag:False,auditFlag:False,sheetMap:" + "[{id:\"402880ee425a92f501425aa75ad60004\",sheetType:\"BASIC\",values:{}}]}"; // 模拟上报的user UserVO user = null; try { user = checkUser("xl1", "1"); } catch (BaseAppException e) { e.printStackTrace(); } // 模拟插件端checkUser String sessionInfo = "{institutionname:\"南昌分行\",institutioncode:\"A01NC\",username:\"肖力1" + "1\",usercode:\"xl1\",rolecode:\"null\",bbhId:\"402855b942099b1b014209b1177e03f5\",bbhcode:\"B01b\",btype:\"BASIC\",taskid:\"402880ee425a92f501425a" + "a75ad50002\",bbhname:\"基层财务b\",bbq:\"" + bbq + "\",frequency:\"MONTH\",SESSIONDIMENSION:{}}"; try { userService.updateSession(sessionInfo, user); } catch (BaseAppException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } // 模拟插件端updateSession // 初始化上报方式 InvokeSource invokeSource = InvokeSource.WSCALL; CreateMulltiTaskReportGroboThread reportThread = new CreateMulltiTaskReportGroboThread(reportMap,user, invokeSource,bbq); tr[processCount] = reportThread; processCount++; } System.out.println("#######################################计时开始########################"); long startTime = System.currentTimeMillis(); // 生成测试线程运行器 MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(tr); // 运行测试线程 try { mttr.runTestRunnables(); } catch (Throwable e) { e.printStackTrace(); } System.out.println("#######################一共耗时:" + String.valueOf((System.currentTimeMillis() - startTime) / 1000) + "秒"); } /** * xl1 1 * */ public UserVO checkUser(String userid, String password) throws BaseAppException { Map<String, String> paramMap = new HashMap<String, String>(); paramMap.put("UserName", userid); paramMap.put("Password", password); List<User> users = userManager.findByCodeCache(userid); List<User> needUsers = new ArrayList<User>(); if (users != null && users.size() > 0) { for (User user : users) { if (user.getState() && user.getCode().equals(userid) && user.getPassword().equals(Encryption.encryption(password))) { needUsers.add(user); } } } // 通过验证 if (needUsers != null && needUsers.size() > 0) { User user = needUsers.get(0); // 获取用户权限,并存放于session中 // UserVO userVO = userManager.getUserPermission(user.getId()); String ipAddress = "0.0.0.0"; UserVO userVO = new UserVO(); BeanUtil2.copyProperties(user, userVO); userVO.setIpAddress(ipAddress); return userVO; // 通过验证 } else { return null; } } } |