@Test public void getExistingBlogEntry() throws Exception { BlogEntry entry = new BlogEntry(); entry.setId(1L); entry.setTitle("Test Title"); Blog blog = new Blog(); blog.setId(1L); entry.setBlog(blog); when(service.findBlogEntry(1L)).thenReturn(entry); mockMvc .perform(get("/rest/blog-entries/1")) .andExpect(jsonPath("$.title", is(entry.getTitle()))) .andExpect( jsonPath( "$.links[*].href", hasItems(endsWith("/blogs/1"), endsWith("/blog-entries/1")))) .andExpect(jsonPath("$.links[*].rel", hasItems(is("self"), is("blog")))) .andExpect(status().isOk()); }
public Blog toBlog() { Blog blog = new Blog(); blog.setTitle(title); return blog; }