Commit a05209de by fsn

对blackboard完成测试

parent 9d7a005b
package com.stylefeng.guns.modular.system.controller;
import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.common.persistence.dao.NoticeMapper;
import com.stylefeng.guns.common.persistence.dao.UserMapper;
import com.stylefeng.guns.modular.system.dao.NoticeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -23,12 +21,6 @@ import java.util.Map;
public class BlackboardController extends BaseController {
@Autowired
UserMapper userMapper;
@Autowired
NoticeMapper noticeMapper;
@Autowired
NoticeDao noticeDao;
/**
......
package com.stylefeng.guns.base;
import com.baomidou.mybatisplus.mapper.SqlRunner;
import com.stylefeng.guns.GunsApplication;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
......@@ -16,6 +16,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GunsApplication.class)
@WebAppConfiguration
@Rollback
public class BaseTest {
@Autowired
......@@ -30,6 +31,5 @@ public class BaseTest {
@Before
public void initDatabase(){
SqlRunner.db().update("");
}
}
package com.stylefeng.guns.system;
import com.stylefeng.guns.base.BaseTest;
import com.stylefeng.guns.modular.system.dao.NoticeDao;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertTrue;
/**
* 首页通知展示测试
......@@ -15,14 +18,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
public class BlackBoardTest extends BaseTest {
@Autowired
NoticeDao noticeDao;
@Test
public void blackBoardTest() {
try {
super.mockMvc.perform(get("/blackboard"))
.andExpect(status().isOk())
.andExpect(model().attributeExists("noticeList"));
} catch (Exception e) {
e.printStackTrace();
}
List<Map<String, Object>> notices = noticeDao.list(null);
assertTrue(notices.size() > 0);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment