Commit 9d7a005b by fsn

测试完善

parent 5b1cbf3a
package com.stylefeng.guns.modular.system.controller; package com.stylefeng.guns.modular.system.controller;
import com.stylefeng.guns.common.controller.BaseController; import com.stylefeng.guns.common.controller.BaseController;
import com.stylefeng.guns.modular.system.dao.NoticeDao;
import com.stylefeng.guns.common.persistence.dao.NoticeMapper; import com.stylefeng.guns.common.persistence.dao.NoticeMapper;
import com.stylefeng.guns.common.persistence.dao.UserMapper; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.common.persistence.model.User;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -37,11 +35,9 @@ public class BlackboardController extends BaseController { ...@@ -37,11 +35,9 @@ public class BlackboardController extends BaseController {
* 跳转到黑板 * 跳转到黑板
*/ */
@RequestMapping("") @RequestMapping("")
public String blackboard() { public String blackboard(Model model) {
List<Map<String, Object>> notices = noticeDao.list(null); List<Map<String, Object>> notices = noticeDao.list(null);
super.setAttr("noticeList",notices); model.addAttribute("noticeList",notices);
super.setAttr("userCount", userMapper.selectCount(new EntityWrapper<User>().notLike("status", "5")));
super.setAttr("systemCount", super.getSystemInvokCount());
return "/blackboard.html"; return "/blackboard.html";
} }
} }
...@@ -37,8 +37,8 @@ spring: ...@@ -37,8 +37,8 @@ spring:
profiles: produce profiles: produce
datasource: datasource:
url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull url: jdbc:mysql://127.0.0.1:3306/guns?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull
username: rootroot username: root
password: rootroot password: root
logging: logging:
level: warn level: warn
......
package com.stylefeng.guns.base; package com.stylefeng.guns.base;
import com.baomidou.mybatisplus.mapper.SqlRunner;
import com.stylefeng.guns.GunsApplication; import com.stylefeng.guns.GunsApplication;
import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GunsApplication.class) @SpringBootTest(classes = GunsApplication.class)
@WebAppConfiguration
public class BaseTest { public class BaseTest {
@Autowired
WebApplicationContext webApplicationContext;
protected MockMvc mockMvc;
@Before
public void setupMockMvc(){
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Before
public void initDatabase(){
SqlRunner.db().update("");
}
} }
package com.stylefeng.guns.system;
import com.stylefeng.guns.base.BaseTest;
import org.junit.Test;
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;
/**
* 首页通知展示测试
*
* @author fengshuonan
* @date 2017-05-21 15:02
*/
public class BlackBoardTest extends BaseTest {
@Test
public void blackBoardTest() {
try {
super.mockMvc.perform(get("/blackboard"))
.andExpect(status().isOk())
.andExpect(model().attributeExists("noticeList"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
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