123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package com.book.server.controller;
- import com.book.dao.utils.TimeUtil;
- import com.book.server.utils.HttpUtils;
- import com.book.server.utils.JsonUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- 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.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 java.nio.charset.StandardCharsets;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.Map;
- import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
- /**
- * created in 2021/9/28
- * Project: book-store
- *
- * @author win7
- */
- @Slf4j
- @RunWith(SpringRunner.class)
- @SpringBootTest
- @AutoConfigureMockMvc
- public class SunControllerTest {
- @Autowired
- private MockMvc mockMvc;
- @Autowired
- private SunDataController sunDataController;
- @Test
- public void testAdd() throws Exception {
- MockMvc mockMvc1 = mockMvc;
- MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/api/sun/secret/deciphering")
- .accept(MediaType.APPLICATION_JSON)
- .param("start_time", "2021-09-27 00:00:00")
- .param("end_time", "2021-09-28 00:00:00"))
- .andExpect(MockMvcResultMatchers.status().isOk())
- .andDo(MockMvcResultHandlers.print())
- .andReturn();
- log.info(mvcResult.getResponse().getContentAsString());
- }
- public void loadData(String from,String to) throws Exception{
- Calendar start = Calendar.getInstance();
- start.setTime(TimeUtil.dateFromStr(from,TimeUtil.YYYY_MM_DD_HH_MM_SS));
- Calendar end = Calendar.getInstance();
- end.setTime(TimeUtil.dateFromStr(to,TimeUtil.YYYY_MM_DD_HH_MM_SS));
- Map<String,String> map = new HashMap<>();
- map.put("start_time",from);
- map.put("end_time",to);
- String jsonStr = JsonUtils.toJsonStr(map);
- System.out.println(jsonStr);
- Map he = new HashMap();
- he.put("Content-Type","application/json");
- HttpUtils.sendPost("http://api.griacxv.cn/api/sun/getData/user_collect",he,jsonStr.getBytes(StandardCharsets.UTF_8));
- start.add(Calendar.HOUR_OF_DAY,1);
- end.add(Calendar.HOUR_OF_DAY,1);
- if ("2021-09-30 12:00:00".equals(TimeUtil.dateToStr(start.getTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS))){
- return;
- }
- Thread.sleep(1000);
- loadData(TimeUtil.dateToStr(start.getTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS),TimeUtil.dateToStr(end.getTime(),TimeUtil.YYYY_MM_DD_HH_MM_SS));
- }
- @Test
- public void load() throws Exception {
- loadData("2021-09-25 00:00:00","2021-09-25 01:00:00");
- }
- }
|