From ac183cbeee0e0a3a69063a5149059e5e14f1fa7d Mon Sep 17 00:00:00 2001 From: Burce Date: Sun, 29 Sep 2019 16:03:26 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=9B=E5=95=86]remove=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iformall/service/test/InvestTests.java | 290 ------------------ .../com/iformall/service/test/SimpleTest.java | 119 ------- .../java/com/iformall/service/test/Test.java | 157 ---------- .../com/iformall/service/test/WebTest.java | 197 ------------ 4 files changed, 763 deletions(-) delete mode 100644 mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java delete mode 100644 mallinkAdmin/src/test/java/com/iformall/service/test/SimpleTest.java delete mode 100644 mallinkAdmin/src/test/java/com/iformall/service/test/Test.java delete mode 100644 mallinkAdmin/src/test/java/com/iformall/service/test/WebTest.java diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java b/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java deleted file mode 100644 index 4fc140e15..000000000 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/InvestTests.java +++ /dev/null @@ -1,290 +0,0 @@ -package com.iformall.service.test; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.iformall.domain.po.*; -import com.iformall.domain.vo.invest.InvestPageResult; -import com.iformall.enums.*; -import com.iformall.mapper.WxBrandMapper; -import com.iformall.service.MallUserInfoService; -import com.iformall.service.invest.*; -import com.iformall.utils.DateUtils; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.util.ThreadContext; -import org.apache.shiro.web.subject.WebSubject; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockHttpSession; -import org.springframework.test.annotation.Rollback; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.context.WebApplicationContext; - -import javax.annotation.Resource; -import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.stream.Collectors; - -@Slf4j -@Rollback(false) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Transactional(rollbackFor = Exception.class) -@RunWith(SpringRunner.class) -@SpringBootTest -public class InvestTests { - @Resource - private org.apache.shiro.mgt.SecurityManager securityManager; - @Resource - private WebApplicationContext webApplicationContext; - private MockHttpServletRequest mockHttpServletRequest; - private MockHttpServletResponse mockHttpServletResponse; - private MockMvc mockMvc; - - @Autowired - InvestCustomerService customerService; - @Autowired - InvestTaskService taskService; - @Autowired - InvestDemandService demandService; - @Autowired - InvestOperateRecordService operateRecordService; - @Autowired - InvestRemindService remindService; - @Autowired - InvestFollowRecordService followRecordService; - @Autowired - MallUserInfoService mallUserInfoService; - @Resource - WxBrandMapper brandMapper; - static final String[] names = {"张三", "李四", "王五", "徐六", "胡八",}; - Random rand = new Random(); - String tenantId = "456"; - - @Before - public void setUp() { - mockHttpServletRequest = new MockHttpServletRequest(webApplicationContext.getServletContext()); - mockHttpServletResponse = new MockHttpServletResponse(); - MockHttpSession mockHttpSession = new MockHttpSession(webApplicationContext.getServletContext()); - mockHttpServletRequest.setSession(mockHttpSession); - SecurityUtils.setSecurityManager(securityManager); - mockMvc = MockMvcBuilders - .webAppContextSetup(webApplicationContext) - .build(); - login("yftest", "123456zz"); - } - - private void login(String username, String password) { - Subject subject = new WebSubject.Builder(mockHttpServletRequest, mockHttpServletResponse) - .buildWebSubject(); - UsernamePasswordToken token = new UsernamePasswordToken(username, password, true); - subject.login(token); - ThreadContext.bind(subject); - } - - @Bean - public List mallUsers() { - MallUserInfo query = new MallUserInfo(); - query.setStatus(1); - query.setIsAdmin(1); - query.setTenantId(tenantId); - return mallUserInfoService.findList(query); - } - - @Bean - public List brands() { - WxBrand query = new WxBrand(); - query.setIsDel(0); - query.setTenantId(tenantId); - return brandMapper.findList(query); - } - - @Test - public void createCustomer() { - //create customer - AtomicLong idCounter = new AtomicLong(10000); - AtomicInteger businessCounter = new AtomicInteger(1); - for (String name : names) { - InvestCustomerEntity customerEntity = new InvestCustomerEntity(); - customerEntity.setBrandId(idCounter.longValue()); - customerEntity.setBusinessId(businessCounter.intValue()); - customerEntity.setName(name); - customerEntity.setTenantId(tenantId); - customerEntity.setPhone("15811234898"); - customerEntity.setInvestChannel(EnumInvestChannel.getEnum(businessCounter.intValue() % 8)); - customerEntity.setRating(EnumCustomerRatingType.getEnum(businessCounter.intValue() % 6)); - customerEntity.setType(EnumCustomerType.getEnum(businessCounter.intValue() / 4)); - customerService.saveOrUpdate(customerEntity); - idCounter.incrementAndGet(); - businessCounter.incrementAndGet(); - } - } - - @Test - public void createTaskBatch() { - List mallUsers = mallUsers(); - AtomicLong idCounter = new AtomicLong(10000); - AtomicInteger businessCounter = new AtomicInteger(1); - for (MallUserInfo userInfo : mallUsers) { - createTask(idCounter.longValue(), JSON.toJSONString(Arrays.asList(userInfo.getId())), businessCounter.intValue(), DateUtils.formatDateTime(new Date())); - idCounter.incrementAndGet(); - businessCounter.incrementAndGet(); - } - } - - private void createTask(Long targetId, String ownerJson, int businessId, String lastDate) { - InvestTaskEntity taskEntity = new InvestTaskEntity(); - taskEntity.setTargetId(targetId); - taskEntity.setOwner(ownerJson); - JSONArray userIds = JSONArray.parseArray(ownerJson); - EnumTaskStatus taskStatus; - if (userIds.size() == 0) { - taskStatus = EnumTaskStatus.CREATED; - } else { - taskStatus = EnumTaskStatus.NEGOTIATING; - } - taskEntity.setStatus(taskStatus); - taskEntity.setTenantId(tenantId); - Map content = Maps.newHashMap(); - content.put("business", businessId); - content.put("lastDate", lastDate); - taskEntity.setContent(JSON.toJSONString(content)); - taskService.save(taskEntity); - } - - @Test - public void createDemand() { - List customers = customerService.list(); - List mallUsers = mallUsers(); - AtomicLong idCounter = new AtomicLong(10000); - AtomicInteger businessCounter = new AtomicInteger(1); - for (MallUserInfo userInfo : mallUsers) { - InvestDemandEntity demandEntity = new InvestDemandEntity(); - demandEntity.setCustomerId(customers.get(rand.nextInt(customers.size())).getId()); - demandEntity.setTargetId(idCounter.longValue()); - demandEntity.setTargetType(EnumInvestType.SHOP); - demandEntity.setOwner(userInfo.getId()); - demandEntity.setTenantId(userInfo.getTenantId()); - Map intent = Maps.newHashMap(); - intent.put("rent_area", 100); //意向租凭面积(平米) - intent.put("opening_time", DateUtils.formatDateTime(new Date())); //预计开业时间 - demandEntity.setIntent(JSON.toJSONString(intent)); - demandService.save(demandEntity); - idCounter.incrementAndGet(); - businessCounter.incrementAndGet(); - } - } - - @Test - public void createRemind() { - List mallUsers = mallUsers(); - AtomicLong idCounter = new AtomicLong(10000); - AtomicInteger businessCounter = new AtomicInteger(1); - for (MallUserInfo userInfo : mallUsers) { - InvestRemindEntity remindEntity = new InvestRemindEntity(); - remindEntity.setBeginDate(new Date()); - remindEntity.setEndDate(new Date()); - remindEntity.setOwner(userInfo.getId()); - remindEntity.setMinute(businessCounter.longValue() * 5); - remindEntity.setTenantId(tenantId); - Map content = Maps.newHashMap(); - content.put("text", "今天约了王老板,目标要签订框架协议"); //文本内容 - content.put("customer_id", idCounter.longValue()); //客户对接人 - content.put("negotiation_type", EnumNegotiationType.COME_VISIT.getCode()); //洽谈方式 - remindEntity.setContent(JSON.toJSONString(content)); - remindService.save(remindEntity); - idCounter.incrementAndGet(); - businessCounter.incrementAndGet(); - } - } - - @Test - public void createFollowRecod() { - List mallUsers = mallUsers(); - List customerEntity = customerService.list(); - AtomicLong idCounter = new AtomicLong(10000); - AtomicInteger businessCounter = new AtomicInteger(1); - for (MallUserInfo userInfo : mallUsers) { - List members = Lists.newArrayList(mallUsers.stream() - .limit(2) - .filter(mallUser -> !Objects.equals(mallUser.getId(), userInfo.getId())) - .collect(Collectors.toList())); - InvestFollowRecordEntity followRecordEntity = new InvestFollowRecordEntity(); - followRecordEntity.setOwner(userInfo.getId()); - followRecordEntity.setTenantId(userInfo.getTenantId()); - followRecordEntity.setType(EnumFollowType.getEnum(businessCounter.intValue() % 2)); - followRecordEntity.setCustomerId(customerEntity.get(rand.nextInt(customerEntity.size())).getId()); - Map content = Maps.newHashMap(); - content.put("date", DateUtils.formatDateTime(new Date())); //文本内容 - content.put("address", "北京"); //客户对接人 - content.put("text", "今天约了王老板,目标要签订框架协议"); //客户对接人 - content.put("document", null); //客户对接人 - content.put("member", members.stream().map(MallUserInfo::getId).collect(Collectors.toList())); //辅谈人 - content.put("negotiation_type", EnumNegotiationType.COME_VISIT.getCode()); //洽谈方式 - followRecordEntity.setContent(JSON.toJSONString(content)); - followRecordService.save(followRecordEntity); - idCounter.incrementAndGet(); - businessCounter.incrementAndGet(); - } - } - - @Autowired - private HttpMessageConverter[] httpMessageConverters; - - @Test - public void query() throws JsonProcessingException { - ObjectMapper mapper = objectMapper(); - - List operates = operateRecordService.queryPage(null); - InvestPageResult follows = followRecordService.queryPage(null); - List customers = customerService.list(null); - List tasks = taskService.list(null); - List reminds = remindService.list(null); - List demands = demandService.list(null); - log.info("operates: {}", mapper.writeValueAsString(operates)); - log.info("follows: {}", mapper.writeValueAsString(follows)); - log.info("customers: {}", mapper.writeValueAsString(customers)); - log.info("tasks: {}", mapper.writeValueAsString(tasks)); - log.info("reminds: {}", mapper.writeValueAsString(reminds)); - log.info("demands: {}", mapper.writeValueAsString(demands)); - } - - @Bean - public ObjectMapper objectMapper() { - MappingJackson2HttpMessageConverter converter = null; - for (HttpMessageConverter httpMessageConverter : httpMessageConverters) { - if (httpMessageConverter instanceof MappingJackson2HttpMessageConverter) - converter = (MappingJackson2HttpMessageConverter) httpMessageConverter; - } - - return converter.getObjectMapper(); - } - - @Test - public void pager() throws Exception { - InvestDemandEntity demandQuery = new InvestDemandEntity(); - demandQuery.setPageNum(1); - demandQuery.setPageSize(10); - InvestPageResult page = demandService.queryPage(demandQuery); - log.debug("page : {}", objectMapper().writeValueAsString(page)); - } -} diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/SimpleTest.java b/mallinkAdmin/src/test/java/com/iformall/service/test/SimpleTest.java deleted file mode 100644 index 3062d2660..000000000 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/SimpleTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.iformall.service.test; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.iformall.domain.po.WxLevelConfig; -import com.iformall.domain.po.WxScoreRules; -import com.iformall.utils.DateUtils; -import lombok.extern.slf4j.Slf4j; -import org.joda.time.Days; -import org.junit.Test; - -import java.math.BigDecimal; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.*; -import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalAdjusters; -import java.util.*; -import java.util.stream.Collectors; - -@Slf4j -public class SimpleTest { - - @Test - public void test() { -// int creditChangeNumOrigin = 1; -// int scoreScale = 12; -// int levelScale = 12; -// int creditChangeNum = new BigDecimal(creditChangeNumOrigin).multiply(new BigDecimal(levelScale)).multiply(new BigDecimal(scoreScale)).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).divide(new BigDecimal(WxLevelConfig.DEFAULT_SCALE), BigDecimal.ROUND_HALF_UP).intValue(); -// log.debug("creditChangeNum -> {}", creditChangeNum); - - int birthdayScale = 11; - float creditScale = new BigDecimal(birthdayScale).divide(new BigDecimal(WxScoreRules.DEFAULT_SCALE)).floatValue(); - log.debug("creditScale -> {}", creditScale); - log.debug("greater -> {}", birthdayScale > WxScoreRules.DEFAULT_SCALE); - } - - @Test - public void test2() { - //List data = Arrays.asList(1, 2, 3, 4, 5, 6); - //data.forEach(d -> { - // if (d == 2) { - // return; - // } - // log.info("d ->{}", d); - //}); - - //String[] data = new String[]{"1", "2"}; - //List dd = Arrays.stream(data).map(Long::parseLong).collect(Collectors.toList()); - //log.info("d ->{}", dd); - - Integer a = 127; - Integer b = 127; - assert a==b ; - } - - @Test - public void test3() { - Date startTime = Date.from(LocalDateTime.now() - .with(TemporalAdjusters.firstDayOfMonth()) - .with(LocalTime.MIN) - .atZone(ZoneId.systemDefault()) - .toInstant()); - Date endTime = Date.from(LocalDateTime.now() - .with(TemporalAdjusters.lastDayOfMonth()) - .with(LocalTime.MAX) - .atZone(ZoneId.systemDefault()) - .toInstant()); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日hh小时mm分钟ss秒"); - log.info("startTime:{}, endTime:{}", formatter.format(startTime), formatter.format(endTime)); - } - - @Test - public void test4() throws ParseException { - String[] days = {"1988/08/21", "2019/08/11", "2019/08/21", "2019/08/13", "2019/08/14", "2019/08/15", "2019/08/16", "2019/08/17", "2019/09/18", "2019/09/10"}; - DateFormat df = new SimpleDateFormat("yyyy/MM/dd"); - int before = 10; - //未来10天时间 - Calendar today = Calendar.getInstance(); - Date begin = today.getTime(); - today.add(Calendar.DAY_OF_YEAR, before); - Date end = today.getTime(); - log.info("begin:{},end:{}", df.format(begin), df.format(end)); - //过去10天时间 - - Calendar today1 = Calendar.getInstance(); - Date end1 = today1.getTime(); - today1.add(Calendar.DAY_OF_YEAR, -before); - Date begin1 = today1.getTime(); - log.info("begin:{},end:{}", df.format(begin1), df.format(end1)); - } - - @Test - public void test5() { - JSONObject jsonObject = new JSONObject(); - JSONArray jsonArray = new JSONArray(); - jsonArray.add(1); - jsonArray.add(2); - jsonArray.add(3); - jsonArray.add(4); - jsonObject.put("couponIds", jsonArray); - jsonObject.put("beforeDays", 4); - List ids = jsonArray.toJavaList(Integer.class); - log.info("data -> {} ", jsonObject.toJSONString()); - log.info("ids -> {} ", JSON.toJSONString(ids)); - } - - @Test - public void test6() { - //Calendar calendar = Calendar.getInstance(); - //calendar.add(Calendar.DAY_OF_YEAR, -1); - //boolean flag = DateUtils.isDateBefore(calendar.getTime()); - //log.info("flag -> {} ", JSON.toJSONString(flag)); - - log.info("uuid {}",UUID.randomUUID()); - } -} diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java b/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java deleted file mode 100644 index 396ebac38..000000000 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/Test.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.iformall.service.test; - -import com.alibaba.fastjson.JSON; -import com.iformall.domain.po.*; -import com.iformall.domain.po.msg.WxMsgRecord; -import com.iformall.domain.vo.WxBillAll; -import com.iformall.enums.*; -import com.iformall.mapper.WxBillSettleMapper; -import com.iformall.mq.MqBaseProducer; -import com.iformall.service.*; -import com.iformall.utils.Constant; -import com.iformall.utils.JsonUtil; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.util.ThreadContext; -import org.apache.shiro.web.subject.WebSubject; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockHttpSession; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import javax.annotation.Resource; -import java.math.BigDecimal; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -@Slf4j -@AutoConfigureMockMvc -@FixMethodOrder(MethodSorters.JVM) -@ActiveProfiles("dev") -@RunWith(SpringRunner.class) -@SpringBootTest -public class Test { - - private static final String TENANT_ID = "456"; - - @Resource - private org.apache.shiro.mgt.SecurityManager securityManager; - @Resource - private WebApplicationContext webApplicationContext; - private MockHttpServletRequest mockHttpServletRequest; - private MockHttpServletResponse mockHttpServletResponse; - - @Autowired - WxLevelConfigService levelConfigService; - - @Autowired - WxCouponSendService wxCouponSendService; - - @Autowired - WxScoreRulesService wxScoreRulesService ; - - private MockMvc mockMvc; - - @Autowired - MqBaseProducer mqBaseProducer; - - @Autowired - private WxBillSettleService wxBillSettleService; - @Autowired - private WxBillAllService wxBillAllService; - @Autowired - private WxBillSettleMapper wxBillSettleMapper; - @Autowired - private WxBillSettleRecordService wxBillSettleRecordService; - - @Autowired - private WxBillPropertyService wxBillPropertyService; - - @Before - public void setUp() { - mockHttpServletRequest = new MockHttpServletRequest(webApplicationContext.getServletContext()); - mockHttpServletResponse = new MockHttpServletResponse(); - MockHttpSession mockHttpSession = new MockHttpSession(webApplicationContext.getServletContext()); - mockHttpServletRequest.setSession(mockHttpSession); - SecurityUtils.setSecurityManager(securityManager); - mockMvc = MockMvcBuilders - .webAppContextSetup(webApplicationContext) - .build(); - login("yftest", "123456zz"); - } - - private void login(String username, String password) { - Subject subject = new WebSubject.Builder(mockHttpServletRequest, mockHttpServletResponse) - .buildWebSubject(); - UsernamePasswordToken token = new UsernamePasswordToken(username, password, true); - subject.login(token); - ThreadContext.bind(subject); - } - - @org.junit.Test - public void levelList() { -// WxBillSettle settle = wxBillSettleService.getById(328411851323572224l); -// log.debug("data:{}", JSON.toJSONString(settle)); -// WxBillAll wxBillAll = new WxBillAll(); -// wxBillAll.setMerchantId(324754110547066880l); -// wxBillAll.setTenantId("456"); -// wxBillAll.setBillTypeValue(10); -// log.debug("data:{}", JSON.toJSONString( wxBillAllService.listBill(wxBillAll))); - -// WxBillSettle wxBillSettle = wxBillSettleService.getById(330875180045271040l); -// -// -// WxBillSettleRecord settleRecord = new WxBillSettleRecord(); -// settleRecord.setSettleId(wxBillSettle.getId()); -// settleRecord.setSettleMoney(wxBillSettle.getBalance()); -// settleRecord.setSettleTime(new Date()); -// settleRecord.setSettleWay(EnumSettleRecordWay.WEBCAT.getCode()); -// settleRecord.setTenantId(wxBillSettle.getTenantId()); -// -// BigDecimal money = new BigDecimal(settleRecord.getSettleMoney()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP); -// settleRecord.setDetail(EnumSettleRecordWay.getEnum(settleRecord.getSettleWay()).getMessage()+"收款"+money.toString()+"元"); -// wxBillSettleRecordService.saveOrUpdate(settleRecord,null,wxBillSettle.getId()); -// -// wxBillSettle.setUpdatetime(new Date()); -// wxBillSettle.setStatus(EnumSettleStatus.FINISH.getCode()); -// wxBillSettleMapper.updateByPrimaryKeySelective(wxBillSettle); - } - - @org.junit.Test - public void testmq(){ - Map dynamicContentMap = new HashMap<>(); - dynamicContentMap.put("page", Constant.adminPage); - WxMsgRecord wxMsgRecord = new WxMsgRecord(); - wxMsgRecord.setMsgType(EnumMsgRecordType.SMS.getCode()); - wxMsgRecord.setModelType(EnumMsgModel.FLOW_ASSIGNEE_NODIFY.getCode()); - wxMsgRecord.setReceiver("18601973448"); - wxMsgRecord.setTenantId("456"); - wxMsgRecord.setDynamicContentMap(dynamicContentMap); - mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(),EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode()); - } - - @org.junit.Test - public void testmq2(){ - - } - - @org.junit.Test - public void testPro(){ - System.out.println("--------"+JsonUtil.obj2Json(wxBillPropertyService.detail(329481088662077445l))); - - } -} diff --git a/mallinkAdmin/src/test/java/com/iformall/service/test/WebTest.java b/mallinkAdmin/src/test/java/com/iformall/service/test/WebTest.java deleted file mode 100644 index 89912023f..000000000 --- a/mallinkAdmin/src/test/java/com/iformall/service/test/WebTest.java +++ /dev/null @@ -1,197 +0,0 @@ -package com.iformall.service.test; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.pagehelper.PageInfo; -import com.iformall.domain.po.*; -import com.iformall.enums.EnumCouponSendSendType; -import com.iformall.enums.EnumCouponSendStatus; -import com.iformall.enums.EnumCouponSendType; -import com.iformall.mapper.WxCouponMapper; -import com.iformall.service.WxCouponSendService; -import com.iformall.service.WxLevelConfigService; -import com.iformall.service.WxScoreRulesService; -import lombok.extern.slf4j.Slf4j; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.authc.UsernamePasswordToken; -import org.apache.shiro.subject.Subject; -import org.apache.shiro.util.ThreadContext; -import org.apache.shiro.web.subject.WebSubject; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.mock.web.MockHttpSession; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultHandlers; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import javax.annotation.Resource; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Slf4j -@AutoConfigureMockMvc -@FixMethodOrder(MethodSorters.JVM) -@ActiveProfiles("dev") -@RunWith(SpringRunner.class) -@SpringBootTest -public class WebTest { - - private static final String TENANT_ID = "456"; - - @Resource - private org.apache.shiro.mgt.SecurityManager securityManager; - @Resource - private WebApplicationContext webApplicationContext; - private MockHttpServletRequest mockHttpServletRequest; - private MockHttpServletResponse mockHttpServletResponse; - - @Autowired - WxLevelConfigService levelConfigService; - - @Autowired - WxCouponSendService wxCouponSendService; - - @Autowired - WxScoreRulesService wxScoreRulesService ; - - private MockMvc mockMvc; - - @Autowired - WxCouponMapper wxCouponMapper ; - - @Before - public void setUp() { - mockHttpServletRequest = new MockHttpServletRequest(webApplicationContext.getServletContext()); - mockHttpServletResponse = new MockHttpServletResponse(); - MockHttpSession mockHttpSession = new MockHttpSession(webApplicationContext.getServletContext()); - mockHttpServletRequest.setSession(mockHttpSession); - SecurityUtils.setSecurityManager(securityManager); - mockMvc = MockMvcBuilders - .webAppContextSetup(webApplicationContext) - .build(); - login("yftest", "123456zz"); - } - - private void login(String username, String password) { - Subject subject = new WebSubject.Builder(mockHttpServletRequest, mockHttpServletResponse) - .buildWebSubject(); - UsernamePasswordToken token = new UsernamePasswordToken(username, password, true); - subject.login(token); - ThreadContext.bind(subject); - } - - @Test - public void levelList() { - WxLevelConfig wxLevelConfig = new WxLevelConfig(); - wxLevelConfig.setTenantId(TENANT_ID); - wxLevelConfig.setSortColumns(BaseEntity.SortField.Points_ASC); - PageInfo data = levelConfigService.listAsPage(wxLevelConfig, 1, 999); - log.debug("data:{}", JSON.toJSONString(data)); - } - - /** - * 投放列表 - */ - @Test - public void list() { - WxCouponSend query = new WxCouponSend(); - query.setSendType(EnumCouponSendSendType.MERCHANT.getCode()); - query.setStatus(EnumCouponSendStatus.VALID.getCode()); - query.setSortColumns(BaseEntity.SortField.CreateDate_DESC); - List pageInfo = wxCouponSendService.listAsPage(query, 0, 10).getList(); - log.info("couponSend list = {}", JSON.toJSONString(pageInfo)); - } - - /** - * 商户注券,添加conditions: {limit:888} - */ - @Test - public void listCouponSend() throws Exception { - MvcResult result = mockMvc.perform( - MockMvcRequestBuilders.get("/wxCouponSend/list") - .param("pageNum", "1") - .param("pageSize", "10") - .param("sortColumn", "createDate") - .param("sortOrder", "desc") - .param("status", "1") - //.param("expired", "1") - .param("sendType", EnumCouponSendSendType.MERCHANT.getCode() + "") - ) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()) - .andReturn(); - String responseStr = result.getResponse().getContentAsString(); - ObjectMapper mapper = new ObjectMapper(); - Map respMap = mapper.readValue(responseStr, Map.class); - log.info("respMap -> {}", JSON.toJSONString(respMap)); - } - - /** - * 商户注券,添加conditions: {limit:888} - */ - @Test - public void addCouponSend() throws Exception { - WxCouponSend wxCouponSend = new WxCouponSend(); - wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode()); - wxCouponSend.setCouponId(267460814401699840L); - wxCouponSend.setTenantId(TENANT_ID); - wxCouponSend.setTitle("口红666"); - wxCouponSend.setCreateDate(new Date()); - wxCouponSend.setUpdateDate(new Date()); - JSONObject jo = new JSONObject(); - jo.put(WxCouponSend.KEY_MERCHANT_LNVENTORY, 994); - - wxCouponSend.setConditions(jo.toJSONString()); - MvcResult result = mockMvc.perform( - MockMvcRequestBuilders.post("/wxCouponSend/add") - .contentType(MediaType.APPLICATION_JSON) - .content(JSON.toJSONString(wxCouponSend))) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()) - .andReturn(); - String responseStr = result.getResponse().getContentAsString(); - ObjectMapper mapper = new ObjectMapper(); - Map respMap = mapper.readValue(responseStr, Map.class); - log.info("respMap -> {}", JSON.toJSONString(respMap)); - } - - @Test - public void add() throws Exception { - Map params = new HashMap<>(); - params.put("creditNum", "1"); - params.put("creditType", "12"); - params.put("cuserId", "329879374400159744"); - params.put("operatorType", "4"); - MvcResult result = mockMvc.perform( - MockMvcRequestBuilders.post("/wxCreditHistory/add") - .contentType(MediaType.APPLICATION_JSON_UTF8) - .content(JSON.toJSONString(params)) - ) - .andExpect(MockMvcResultMatchers.status().isOk()) - .andDo(MockMvcResultHandlers.print()) - .andReturn(); - String responseStr = result.getResponse().getContentAsString(); - ObjectMapper mapper = new ObjectMapper(); - Map respMap = mapper.readValue(responseStr, Map.class); - log.info("respMap -> {}", JSON.toJSONString(respMap)); - } - -}