package readinglist;
import static org.hamcrest.Matchers.*;
import static org.springframework.http.MediaType.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
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;
import readinglist.ReadingListApplication;
import readinglist.Book;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ReadingListApplication.class)
@WebAppConfiguration
public class MockMvcWebTests {
@Autowired
WebApplicationContext webContext;
private MockMvc mockMvc;
@Before
public void setupMockMvc() {
mockMvc = MockMvcBuilders
.webAppContextSetup(webContext)
.build();
}
@Test
public void redirectFromRoot() throws Exception {
mockMvc.perform(get("/"))
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/readingList"));
}
@Test
public void homePage() throws Exception {
mockMvc.perform(get("/readingList"))
.andExpect(status().isOk())
.andExpect(view().name("readingList"))
.andExpect(model().attributeExists("books"))
.andExpect(model().attribute("books", is(empty())));
}
@Test
public void postBook() throws Exception {
mockMvc.perform(post("/readingList")
.contentType(APPLICATION_FORM_URLENCODED)
.param("title", "BOOK TITLE")
.param("author", "BOOK AUTHOR")
.param("isbn", "1234567890")
.param("description", "DESCRIPTION"))
.andExpect(status().is3xxRedirection())
.andExpect(header().string("Location", "/readingList"));
Book expectedBook = new Book();
expectedBook.setId(1L);
expectedBook.setReader("craig");
expectedBook.setTitle("BOOK TITLE");
expectedBook.setAuthor("BOOK AUTHOR");
expectedBook.setIsbn("1234567890");
expectedBook.setDescription("DESCRIPTION");
mockMvc.perform(get("/readingList"))
.andExpect(status().isOk())
.andExpect(view().name("readingList"))
.andExpect(model().attributeExists("books"))
.andExpect(model().attribute("books", hasSize(1)))
.andExpect(model().attribute("books",
contains(samePropertyValuesAs(expectedBook))));
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
SpringBoot实战 源码下载
共247个文件
java:79个
groovy:33个
html:24个
4星 · 超过85%的资源 需积分: 47 35 下载量 57 浏览量
2018-11-16
16:04:55
上传
评论
收藏 963KB ZIP 举报
温馨提示
图灵程序系列 Springboot实战中的几个demo代码,整理了一下分享给大家,看书的同时实战操作一下是事半功倍的。祝大家学习JAVA愉快啦~
资源推荐
资源详情
资源评论
收起资源包目录
SpringBoot实战 源码下载 (247个子文件)
gradlew.bat 2KB
main.css 11KB
errors.css 2KB
mobile.css 2KB
application.css 438B
style.css 298B
style.css 298B
style.css 298B
style.css 298B
style.css 298B
style.css 298B
style.css 206B
style.css 206B
style.css 206B
style.css 206B
.DS_Store 6KB
spinner.gif 2KB
sorted_asc.gif 835B
sorted_desc.gif 834B
.gitignore 54B
.gitignore 54B
.gitignore 54B
.gitignore 54B
.gitignore 54B
.gitignore 54B
.gitignore 54B
.gitignore 54B
build.gradle 2KB
build.gradle 2KB
build.gradle 2KB
build.gradle 2KB
build.gradle 1KB
build.gradle 1KB
build.gradle 1KB
build.gradle 1KB
build.gradle 1KB
gradlew 5KB
ReadingListController.groovy 1KB
ReadingListControllerSpec.groovy 1KB
ReadingListControllerSpec.groovy 1KB
Application.groovy 1KB
ReadingListControllerTest.groovy 1KB
ReadingListControllerTest.groovy 1KB
ReaderHandlerMethodArgumentResolver.groovy 1012B
SecurityConfig.groovy 1011B
JdbcReadingListRepository.groovy 885B
JdbcReadingListRepository.groovy 885B
logback.groovy 735B
Reader.groovy 658B
ReadingListController.groovy 587B
ReadingListController.groovy 587B
CustomErrorAttributes.groovy 542B
ReadingListControllerSpec.groovy 420B
BookSpec.groovy 390B
ReadingListController.groovy 355B
UrlMappings.groovy 283B
AmazonConfig.groovy 280B
Application.groovy 239B
Grabs.groovy 216B
Book.groovy 161B
Book.groovy 152B
HelloController.groovy 104B
Book.groovy 100B
ReadingListRepository.groovy 100B
Book.groovy 100B
ReadingListRepository.groovy 100B
BootStrap.groovy 88B
Hi.groovy 72B
Grabs.groovy 65B
resources.groovy 47B
index.gsp 4KB
index.gsp 2KB
readingList.gsp 1KB
error.gsp 1KB
main.gsp 834B
login.gsp 743B
error.gsp 378B
notFound.gsp 375B
profile.gsp 44B
readingList.html 2KB
readingList.html 2KB
readingList.html 2KB
readingList.html 2KB
readingList.html 2KB
readingList.html 1KB
readingList.html 1KB
readingList.html 1KB
readingList.html 1KB
login.html 762B
login.html 762B
login.html 762B
login.html 762B
login.html 762B
error.html 440B
error.html 440B
error.html 440B
error.html 440B
error.html 440B
profile.html 77B
profile.html 77B
共 247 条
- 1
- 2
- 3
资源评论
- hhn9252019-05-23挺好的11111
黑羽灬快斗
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Arduino Nano的红外循迹小车源码(高分课设).zip
- 将MS SQL数据库表里的数据内容生成SQL执行语句
- 基于MATLAB的钢板表面缺陷检测系统
- MS SQL里生成行政区域县区信息表和相应数据
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功