You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
194 lines
5.9 KiB
194 lines
5.9 KiB
package com.community.pocket;
|
|
|
|
import com.community.pocket.entity.po.Forum;
|
|
import com.community.pocket.entity.po.android.Garbage;
|
|
import com.community.pocket.entity.po.android.GarbageWastePrice;
|
|
import com.community.pocket.entity.vo.android.GarbageCateGory;
|
|
import com.community.pocket.entity.vo.android.QueryUserForm;
|
|
import com.community.pocket.repository.android.GarbageDao;
|
|
import com.community.pocket.repository.android.GarbagePriceDao;
|
|
import com.community.pocket.repository.android.UserDao;
|
|
import com.community.pocket.repository.android.VisitorPeopleDao;
|
|
import com.community.pocket.util.MessageService;
|
|
import com.google.gson.Gson;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.InputStreamReader;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
//SpringBoot1.4版本之前用的是SpringJUnit4ClassRunner.class
|
|
//@RunWith(SpringRunner.class)
|
|
//SpringBoot1.4版本之前用的是@SpringApplicationConfiguration(classes = Application.class)
|
|
@SpringBootTest
|
|
//测试环境使用,用来表示测试环境使用的ApplicationContext将是WebApplicationContext类型的
|
|
@WebAppConfiguration
|
|
class DemoApplicationTests {
|
|
|
|
@Autowired
|
|
private UserDao userDao;
|
|
|
|
@Autowired
|
|
private VisitorPeopleDao visitorPeopleDao;
|
|
|
|
@Autowired
|
|
private GarbageDao garbageDao;
|
|
|
|
@Autowired
|
|
private GarbagePriceDao garbagePriceDao;
|
|
|
|
@Autowired
|
|
private MessageService messageService;
|
|
|
|
@Autowired
|
|
private WebApplicationContext webApplicationContext;
|
|
|
|
private MockMvc mockMvc;
|
|
|
|
@BeforeEach
|
|
public void setup() {
|
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(
|
|
webApplicationContext).build();
|
|
}
|
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(DemoApplicationTests.class);
|
|
|
|
@Test
|
|
void contextLoads() {
|
|
}
|
|
|
|
@Test
|
|
void queryUser() {
|
|
QueryUserForm queryUserForm = new QueryUserForm();
|
|
queryUserForm.setName("p");
|
|
userDao.queryUser(queryUserForm);
|
|
}
|
|
|
|
@Test
|
|
void showTime() {
|
|
List<String> s = visitorPeopleDao.getVisitorList();
|
|
LOG.info(String.join(",", s));
|
|
}
|
|
|
|
// 初始化垃圾数据
|
|
@Test
|
|
void loadData() throws FileNotFoundException {
|
|
Gson gson = new Gson();
|
|
MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class);
|
|
for (Garbage garbage : g.getList()) {
|
|
garbageDao.save(garbage);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void loadPriceData() {
|
|
for (int i = 0; i < 100; i++) {
|
|
GarbageWastePrice price = new GarbageWastePrice();
|
|
price.setName(RandomStringUtils.randomAlphabetic(6));
|
|
price.setPrice(new Random().nextInt(100) * 1F);
|
|
garbagePriceDao.save(price);
|
|
}
|
|
}
|
|
|
|
@Test
|
|
void testMessage() {
|
|
LOG.info(messageService.getMessage(GarbageCateGory.type1));
|
|
}
|
|
|
|
@Test
|
|
//测试添加活动贴
|
|
void testActive() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendActive")
|
|
.param("activeStartTime", "2020/01/01")
|
|
.param("activeEndTime", "2020/01/02")
|
|
.param("activeScore", "15")
|
|
.param("title", "666")
|
|
.param("content", "fuckfuckfuckfuckfuck")
|
|
.param("username", "panqihua")
|
|
.param("token", "b6a518fffa3ffa607e756324474e9484")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
@Test
|
|
//测试添加投诉贴
|
|
void testComplain() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendComplain")
|
|
.param("complain", "panqihua")
|
|
.param("title", "666")
|
|
.param("content", "fuckfuckfuckfuckfuck")
|
|
.param("token", "b6a518fffa3ffa607e756324474e9484")
|
|
.param("username", "panqihua")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//测试发送动态
|
|
@Test
|
|
void testTopic() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.post("/forum/sendTopic")
|
|
.param("title", "666")
|
|
.param("content", "fuckfuckfuckfuckfuck")
|
|
.param("token", "b6a518fffa3ffa607e756324474e9484")
|
|
.param("username", "panqihua")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//测试查询帖子
|
|
@Test
|
|
void queryForum() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.get("/api/forum/posts")
|
|
.param("status", Forum.ForumStatus.ok.name())
|
|
.param("currentPage", "1")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//测试登陆
|
|
@Test
|
|
void login() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.post("/login")
|
|
.param("username", "panqihua")
|
|
.param("password", "123456")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//测试垃圾分类查询
|
|
@Test
|
|
void queryGarbage() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.get("/garbage/sorting")
|
|
.param("name", "安")
|
|
).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//测试检索预约人
|
|
@Test
|
|
void queryPeople() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.get("/visitor/people")
|
|
.param("name", "p")
|
|
.param("outPeople", String.valueOf(false))).andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
|
|
//加载访客信息
|
|
@Test
|
|
void queryVisitor() throws Exception {
|
|
mockMvc.perform(MockMvcRequestBuilders.get("/visitor/reservation")
|
|
.param("username", "panqihua")
|
|
.param("token", "e3c8ed5a74841556c57de6e17b166f68")
|
|
.param("startDate", "2020/04/18")
|
|
.param("endDate", "2020/04/19"))
|
|
.andDo(MockMvcResultHandlers.print()).andReturn();
|
|
}
|
|
}
|
|
|