Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Autowired
- private AccountService accountService;
- @RunWith(SpringJUnit4ClassRunner.class)
- @SpringApplicationConfiguration(classes = MockServletContext.class)
- @WebAppConfiguration
- public class AccountControllerITest {
- private MockMvc mvc;
- ObjectMapper om;
- @Before
- public void setUp() throws Exception {
- mvc = MockMvcBuilders.standaloneSetup(new AccountController()).build();
- }
- @Test
- public void getAccounts() throws Exception {
- MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/api/accounts"))
- .andExpect(status().isOk())
- .andReturn();
- }
- }
- @RestController
- @RequestMapping("/api/accounts")
- public class AccountController {
- @Autowired
- private AccountService accountService;
- @RequestMapping(method = RequestMethod.GET)
- public ResponseEntity<Set<AccountInfo>> getAccounts(@RequestParam(value = "firstName", required = false) String firstName,
- @RequestParam(value = "surName", required = false) String surName) {
- Set<AccountInfo> accounts = accountService.getAccounts(firstName, surName);
- return new ResponseEntity<>(accounts, HttpStatus.OK);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement