Commit a05209de by fsn

对blackboard完成测试

parent 9d7a005b
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.common.persistence.dao.NoticeMapper;
import com.stylefeng.guns.common.persistence.dao.UserMapper;
import com.stylefeng.guns.modular.system.dao.NoticeDao; 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;
...@@ -23,12 +21,6 @@ import java.util.Map; ...@@ -23,12 +21,6 @@ import java.util.Map;
public class BlackboardController extends BaseController { public class BlackboardController extends BaseController {
@Autowired @Autowired
UserMapper userMapper;
@Autowired
NoticeMapper noticeMapper;
@Autowired
NoticeDao noticeDao; NoticeDao noticeDao;
/** /**
......
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.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; 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.annotation.Rollback;
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.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -16,6 +16,7 @@ import org.springframework.web.context.WebApplicationContext; ...@@ -16,6 +16,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = GunsApplication.class) @SpringBootTest(classes = GunsApplication.class)
@WebAppConfiguration @WebAppConfiguration
@Rollback
public class BaseTest { public class BaseTest {
@Autowired @Autowired
...@@ -30,6 +31,5 @@ public class BaseTest { ...@@ -30,6 +31,5 @@ public class BaseTest {
@Before @Before
public void initDatabase(){ public void initDatabase(){
SqlRunner.db().update("");
} }
} }
package com.stylefeng.guns.system; package com.stylefeng.guns.system;
import com.stylefeng.guns.base.BaseTest; import com.stylefeng.guns.base.BaseTest;
import com.stylefeng.guns.modular.system.dao.NoticeDao;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; import java.util.Map;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.junit.Assert.assertTrue;
/** /**
* 首页通知展示测试 * 首页通知展示测试
...@@ -15,14 +18,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. ...@@ -15,14 +18,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/ */
public class BlackBoardTest extends BaseTest { public class BlackBoardTest extends BaseTest {
@Autowired
NoticeDao noticeDao;
@Test @Test
public void blackBoardTest() { public void blackBoardTest() {
try { List<Map<String, Object>> notices = noticeDao.list(null);
super.mockMvc.perform(get("/blackboard")) assertTrue(notices.size() > 0);
.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