Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. @Autowired
  2. private AccountService accountService;
  3.  
  4. @RunWith(SpringJUnit4ClassRunner.class)
  5. @SpringApplicationConfiguration(classes = MockServletContext.class)
  6. @WebAppConfiguration
  7. public class AccountControllerITest {
  8.  
  9. private MockMvc mvc;
  10.  
  11. ObjectMapper om;
  12.  
  13. @Before
  14. public void setUp() throws Exception {
  15. mvc = MockMvcBuilders.standaloneSetup(new AccountController()).build();
  16. }
  17.  
  18. @Test
  19. public void getAccounts() throws Exception {
  20. MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/api/accounts"))
  21. .andExpect(status().isOk())
  22. .andReturn();
  23. }
  24. }
  25.  
  26. @RestController
  27. @RequestMapping("/api/accounts")
  28. public class AccountController {
  29.  
  30. @Autowired
  31. private AccountService accountService;
  32.  
  33. @RequestMapping(method = RequestMethod.GET)
  34. public ResponseEntity<Set<AccountInfo>> getAccounts(@RequestParam(value = "firstName", required = false) String firstName,
  35. @RequestParam(value = "surName", required = false) String surName) {
  36. Set<AccountInfo> accounts = accountService.getAccounts(firstName, surName);
  37. return new ResponseEntity<>(accounts, HttpStatus.OK);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement