method2testcases stringlengths 118 3.08k |
|---|
### Question:
Travel2ServiceImpl implements Travel2Service { @Override public Response delete(String tripId, HttpHeaders headers) { TripId ti = new TripId(tripId); if (repository.findByTripId(ti) != null) { repository.deleteByTripId(ti); return new Response<>(1, "Delete trip:" + tripId + ".", tripId); } else { return new Response<>(0, "Trip " + tripId + " doesn't exist.", null); } } @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testDelete1() { Trip trip = new Trip(); Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(trip); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).deleteByTripId(Mockito.any(TripId.class)); Response result = travel2ServiceImpl.delete("trip_id_1", headers); Assert.assertEquals(new Response<>(1, "Delete trip:trip_id_1.", "trip_id_1"), result); }
@Test public void testDelete2() { Mockito.when(repository.findByTripId(Mockito.any(TripId.class))).thenReturn(null); Response result = travel2ServiceImpl.delete("trip_id_1", headers); Assert.assertEquals(new Response<>(0, "Trip trip_id_1 doesn't exist.", null), result); } |
### Question:
Travel2ServiceImpl implements Travel2Service { @Override public Response queryAll(HttpHeaders headers) { List<Trip> tripList = repository.findAll(); if (tripList != null && !tripList.isEmpty()) { return new Response<>(1, success, tripList); } return new Response<>(0, noCnontent, null); } @Override Response getRouteByTripId(String tripId, HttpHeaders headers); @Override Response getTrainTypeByTripId(String tripId, HttpHeaders headers); @Override Response getTripByRoute(ArrayList<String> routeIds, HttpHeaders headers); @Override Response create(TravelInfo info, HttpHeaders headers); @Override Response retrieve(String tripId, HttpHeaders headers); @Override Response update(TravelInfo info, HttpHeaders headers); @Override Response delete(String tripId, HttpHeaders headers); @Override Response query(TripInfo info, HttpHeaders headers); @Override Response getTripAllDetailInfo(TripAllDetailInfo gtdi, HttpHeaders headers); @Override Response queryAll(HttpHeaders headers); @Override Response adminQueryAll(HttpHeaders headers); }### Answer:
@Test public void testQueryAll1() { ArrayList<Trip> tripList = new ArrayList<>(); tripList.add(new Trip()); Mockito.when(repository.findAll()).thenReturn(tripList); Response result = travel2ServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(1, success, tripList), result); }
@Test public void testQueryAll2() { Mockito.when(repository.findAll()).thenReturn(null); Response result = travel2ServiceImpl.queryAll(headers); Assert.assertEquals(new Response<>(0, noCnontent, null), result); } |
### Question:
StationServiceImpl implements StationService { @Override public boolean exist(String stationName, HttpHeaders headers) { boolean result = false; if (repository.findByName(stationName) != null) { result = true; } return result; } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testExist1() { Station station = new Station(); Mockito.when(repository.findByName(Mockito.anyString())).thenReturn(station); Assert.assertTrue(stationServiceImpl.exist("station_name", headers)); }
@Test public void testExist2() { Mockito.when(repository.findByName(Mockito.anyString())).thenReturn(null); Assert.assertFalse(stationServiceImpl.exist("station_name", headers)); } |
### Question:
SeatController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ Seat Service ] !"; } @GetMapping(path = "/welcome") String home(); @CrossOrigin(origins = "*") @PostMapping(value = "/seats") HttpEntity create(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/seats/left_tickets") HttpEntity getLeftTicketOfInterval(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/seatservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Seat Service ] !")); } |
### Question:
SeatController { @CrossOrigin(origins = "*") @PostMapping(value = "/seats") public HttpEntity create(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers) { return ok(seatService.distributeSeat(seatRequest, headers)); } @GetMapping(path = "/welcome") String home(); @CrossOrigin(origins = "*") @PostMapping(value = "/seats") HttpEntity create(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/seats/left_tickets") HttpEntity getLeftTicketOfInterval(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCreate() throws Exception { Seat seatRequest = new Seat(); Mockito.when(seatService.distributeSeat(Mockito.any(Seat.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(seatRequest); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/seatservice/seats").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
SeatController { @CrossOrigin(origins = "*") @PostMapping(value = "/seats/left_tickets") public HttpEntity getLeftTicketOfInterval(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers) { return ok(seatService.getLeftTicketOfInterval(seatRequest, headers)); } @GetMapping(path = "/welcome") String home(); @CrossOrigin(origins = "*") @PostMapping(value = "/seats") HttpEntity create(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/seats/left_tickets") HttpEntity getLeftTicketOfInterval(@RequestBody Seat seatRequest, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetLeftTicketOfInterval() throws Exception { Seat seatRequest = new Seat(); Mockito.when(seatService.getLeftTicketOfInterval(Mockito.any(Seat.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(seatRequest); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/seatservice/seats/left_tickets").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TicketInfoServiceImpl implements TicketInfoService { @Override public Response queryForTravel(Travel info, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(info, headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class); return re.getBody(); } @Override Response queryForTravel(Travel info, HttpHeaders headers); @Override Response queryForStationId(String name, HttpHeaders headers); }### Answer:
@Test public void testQueryForTravel() { Travel info = new Travel(); HttpEntity requestEntity = new HttpEntity(info, headers); Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); Response result = ticketInfoServiceImpl.queryForTravel(info, headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
TicketInfoServiceImpl implements TicketInfoService { @Override public Response queryForStationId(String name, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class); return re.getBody(); } @Override Response queryForTravel(Travel info, HttpHeaders headers); @Override Response queryForStationId(String name, HttpHeaders headers); }### Answer:
@Test public void testQueryForStationId() { HttpEntity requestEntity = new HttpEntity(headers); Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when( restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); Response result = ticketInfoServiceImpl.queryForStationId("name", headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
TicketInfoController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ TicketInfo Service ] !"; } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/ticketinfo") HttpEntity queryForTravel(@RequestBody Travel info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/ticketinfo/{name}") HttpEntity queryForStationId(@PathVariable String name, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/ticketinfoservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ TicketInfo Service ] !")); } |
### Question:
TicketInfoController { @PostMapping(value = "/ticketinfo") public HttpEntity queryForTravel(@RequestBody Travel info, @RequestHeader HttpHeaders headers) { return ok(service.queryForTravel(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/ticketinfo") HttpEntity queryForTravel(@RequestBody Travel info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/ticketinfo/{name}") HttpEntity queryForStationId(@PathVariable String name, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryForTravel() throws Exception { Travel info = new Travel(); Mockito.when(service.queryForTravel(Mockito.any(Travel.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/ticketinfoservice/ticketinfo").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TicketInfoController { @GetMapping(value = "/ticketinfo/{name}") public HttpEntity queryForStationId(@PathVariable String name, @RequestHeader HttpHeaders headers) { return ok(service.queryForStationId(name, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/ticketinfo") HttpEntity queryForTravel(@RequestBody Travel info, @RequestHeader HttpHeaders headers); @GetMapping(value = "/ticketinfo/{name}") HttpEntity queryForStationId(@PathVariable String name, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryForStationId() throws Exception { Mockito.when(service.queryForStationId(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/ticketinfoservice/ticketinfo/name")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminRouteServiceImpl implements AdminRouteService { @Override public Response getAllRoutes(HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class); return re.getBody(); } @Override Response getAllRoutes(HttpHeaders headers); @Override Response createAndModifyRoute(RouteInfo request, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); }### Answer:
@Test public void testGetAllRoutes() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); Response result = adminRouteServiceImpl.getAllRoutes(headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminRouteServiceImpl implements AdminRouteService { @Override public Response createAndModifyRoute(RouteInfo request, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(request, headers); ResponseEntity<Response<Route>> re = restTemplate.exchange( "http: HttpMethod.POST, requestEntity, new ParameterizedTypeReference<Response<Route>>() { }); return re.getBody(); } @Override Response getAllRoutes(HttpHeaders headers); @Override Response createAndModifyRoute(RouteInfo request, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); }### Answer:
@Test public void testCreateAndModifyRoute() { RouteInfo request = new RouteInfo(); HttpEntity requestEntity2 = new HttpEntity(request, headers); ResponseEntity<Response<Route>> re2 = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, new ParameterizedTypeReference<Response<Route>>() { })).thenReturn(re2); Response result = adminRouteServiceImpl.createAndModifyRoute(request, headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminRouteServiceImpl implements AdminRouteService { @Override public Response deleteRoute(String routeId, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); return re.getBody(); } @Override Response getAllRoutes(HttpHeaders headers); @Override Response createAndModifyRoute(RouteInfo request, HttpHeaders headers); @Override Response deleteRoute(String routeId, HttpHeaders headers); }### Answer:
@Test public void testDeleteRoute() { Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminRouteServiceImpl.deleteRoute("routeId", headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminRouteController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ AdminRoute Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminroute") HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminroute") HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminroute/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminrouteservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ AdminRoute Service ] !")); } |
### Question:
AdminRouteController { @CrossOrigin(origins = "*") @GetMapping(path = "/adminroute") public HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers) { return ok(adminRouteService.getAllRoutes(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminroute") HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminroute") HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminroute/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllRoutes() throws Exception { Mockito.when(adminRouteService.getAllRoutes(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminrouteservice/adminroute")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminRouteController { @PostMapping(value = "/adminroute") public HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers) { return ok(adminRouteService.createAndModifyRoute(request, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminroute") HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminroute") HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminroute/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testAddRoute() throws Exception { RouteInfo request = new RouteInfo(); Mockito.when(adminRouteService.createAndModifyRoute(Mockito.any(RouteInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(request); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/adminrouteservice/adminroute").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminRouteController { @DeleteMapping(value = "/adminroute/{routeId}") public HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers) { return ok(adminRouteService.deleteRoute(routeId, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminroute") HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminroute") HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminroute/{routeId}") HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteRoute() throws Exception { Mockito.when(adminRouteService.deleteRoute(Mockito.anyString(),Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/adminrouteservice/adminroute/routeId")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
StationServiceImpl implements StationService { @Override public Response update(Station info, HttpHeaders headers) { if (repository.findById(info.getId()) == null) { return new Response<>(0, "Station not exist", null); } else { Station station = new Station(info.getId(), info.getName()); station.setStayTime(info.getStayTime()); repository.save(station); return new Response<>(1, "Update success", station); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testUpdate1() { Station info = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); Response result = stationServiceImpl.update(info, headers); Assert.assertEquals(new Response<>(0, "Station not exist", null), result); }
@Test public void testUpdate2() { Station info = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(info); Mockito.when(repository.save(Mockito.any(Station.class))).thenReturn(null); Response result = stationServiceImpl.update(info, headers); Assert.assertEquals("Update success", result.getMsg()); } |
### Question:
AdminUserServiceImpl implements AdminUserService { @Override public Response getAllUsers(HttpHeaders headers) { AdminUserServiceImpl.LOGGER.info("[Admin User Service][Get All Users]"); HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response<List<User>>> re = restTemplate.exchange( USER_SERVICE_IP_URI, HttpMethod.GET, requestEntity, new ParameterizedTypeReference<Response<List<User>>>() { }); return re.getBody(); } @Override Response getAllUsers(HttpHeaders headers); @Override Response deleteUser(String userId, HttpHeaders headers); @Override Response updateUser(UserDto userDto, HttpHeaders headers); @Override Response addUser(UserDto userDto, HttpHeaders headers); }### Answer:
@Test public void testGetAllUsers() { Response<List<User>> response = new Response<>(); ResponseEntity<Response<List<User>>> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, new ParameterizedTypeReference<Response<List<User>>>() { })).thenReturn(re); Response result = adminUserServiceImpl.getAllUsers(headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminUserServiceImpl implements AdminUserService { @Override public Response deleteUser(String userId, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( USER_SERVICE_IP_URI + "/" + userId, HttpMethod.DELETE, requestEntity, Response.class); return re.getBody(); } @Override Response getAllUsers(HttpHeaders headers); @Override Response deleteUser(String userId, HttpHeaders headers); @Override Response updateUser(UserDto userDto, HttpHeaders headers); @Override Response addUser(UserDto userDto, HttpHeaders headers); }### Answer:
@Test public void testDeleteUser() { Response response = new Response<>(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminUserServiceImpl.deleteUser("userId", headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminUserServiceImpl implements AdminUserService { @Override public Response updateUser(UserDto userDto, HttpHeaders headers) { LOGGER.info("UPDATE USER: " + userDto.toString()); HttpEntity requestEntity = new HttpEntity(userDto, headers); ResponseEntity<Response> re = restTemplate.exchange( USER_SERVICE_IP_URI, HttpMethod.PUT, requestEntity, Response.class); return re.getBody(); } @Override Response getAllUsers(HttpHeaders headers); @Override Response deleteUser(String userId, HttpHeaders headers); @Override Response updateUser(UserDto userDto, HttpHeaders headers); @Override Response addUser(UserDto userDto, HttpHeaders headers); }### Answer:
@Test public void testUpdateUser() { UserDto userDto = new UserDto(); HttpEntity requestEntity2 = new HttpEntity(userDto, headers); Response response = new Response<>(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity2, Response.class)).thenReturn(re); Response result = adminUserServiceImpl.updateUser(userDto, headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminUserServiceImpl implements AdminUserService { @Override public Response addUser(UserDto userDto, HttpHeaders headers) { LOGGER.info("ADD USER INFO : "+userDto.toString()); HttpEntity requestEntity = new HttpEntity(userDto, headers); ResponseEntity<Response<User>> re = restTemplate.exchange( USER_SERVICE_IP_URI + "/register", HttpMethod.POST, requestEntity, new ParameterizedTypeReference<Response<User>>() { }); return re.getBody(); } @Override Response getAllUsers(HttpHeaders headers); @Override Response deleteUser(String userId, HttpHeaders headers); @Override Response updateUser(UserDto userDto, HttpHeaders headers); @Override Response addUser(UserDto userDto, HttpHeaders headers); }### Answer:
@Test public void testAddUser() { UserDto userDto = new UserDto(); HttpEntity requestEntity2 = new HttpEntity(userDto, headers); Response<User> response = new Response<>(); ResponseEntity<Response<User>> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity2, new ParameterizedTypeReference<Response<User>>() { })).thenReturn(re); Response result = adminUserServiceImpl.addUser(userDto, headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminUserController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ AdminUser Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping HttpEntity getAllUsers(@RequestHeader HttpHeaders headers); @PutMapping HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @PostMapping HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/{userId}") HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminuserservice/users/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ AdminUser Service ] !")); } |
### Question:
AdminUserController { @CrossOrigin(origins = "*") @GetMapping public HttpEntity getAllUsers(@RequestHeader HttpHeaders headers) { return ok(adminUserService.getAllUsers(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping HttpEntity getAllUsers(@RequestHeader HttpHeaders headers); @PutMapping HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @PostMapping HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/{userId}") HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllUsers() throws Exception { Mockito.when(adminUserService.getAllUsers(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminuserservice/users")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminUserController { @PutMapping public HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers) { return ok(adminUserService.updateUser(userDto, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping HttpEntity getAllUsers(@RequestHeader HttpHeaders headers); @PutMapping HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @PostMapping HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/{userId}") HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdateUser() throws Exception { UserDto userDto = new UserDto(); Mockito.when(adminUserService.updateUser(Mockito.any(UserDto.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(userDto); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/adminuserservice/users").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminUserController { @PostMapping public HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers) { return ok(adminUserService.addUser(userDto, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping HttpEntity getAllUsers(@RequestHeader HttpHeaders headers); @PutMapping HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @PostMapping HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/{userId}") HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testAddUser() throws Exception { UserDto userDto = new UserDto(); Mockito.when(adminUserService.addUser(Mockito.any(UserDto.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(userDto); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/adminuserservice/users").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminUserController { @DeleteMapping(value = "/{userId}") public HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers) { return ok(adminUserService.deleteUser(userId, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping HttpEntity getAllUsers(@RequestHeader HttpHeaders headers); @PutMapping HttpEntity updateUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @PostMapping HttpEntity addUser(@RequestBody UserDto userDto, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/{userId}") HttpEntity deleteUser(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteUser() throws Exception { Mockito.when(adminUserService.deleteUser(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/adminuserservice/users/user_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RoutePlanController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ RoutePlan Service ] !"; } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/routePlan/cheapestRoute") HttpEntity getCheapestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/quickestRoute") HttpEntity getQuickestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/minStopStations") HttpEntity getMinStopStations(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/routeplanservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ RoutePlan Service ] !")); } |
### Question:
RoutePlanController { @PostMapping(value = "/routePlan/cheapestRoute") public HttpEntity getCheapestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers) { RoutePlanController.LOGGER.info("[Route Plan Service][Get Cheapest Routes] From: {} To: {} Num: {} Date: {}", info.getFormStationName(), info.getToStationName(), + info.getNum(), info.getTravelDate()); return ok(routePlanService.searchCheapestResult(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/routePlan/cheapestRoute") HttpEntity getCheapestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/quickestRoute") HttpEntity getQuickestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/minStopStations") HttpEntity getMinStopStations(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetCheapestRoutes() throws Exception { RoutePlanInfo info = new RoutePlanInfo(); Mockito.when(routePlanService.searchCheapestResult(Mockito.any(RoutePlanInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/routeplanservice/routePlan/cheapestRoute").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RoutePlanController { @PostMapping(value = "/routePlan/quickestRoute") public HttpEntity getQuickestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers) { RoutePlanController.LOGGER.info("[Route Plan Service][Get Quickest Routes] From: {} To: {} Num: {} Date: {}", info.getFormStationName(), info.getToStationName(), info.getNum(), info.getTravelDate()); return ok(routePlanService.searchQuickestResult(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/routePlan/cheapestRoute") HttpEntity getCheapestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/quickestRoute") HttpEntity getQuickestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/minStopStations") HttpEntity getMinStopStations(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetQuickestRoutes() throws Exception { RoutePlanInfo info = new RoutePlanInfo(); Mockito.when(routePlanService.searchQuickestResult(Mockito.any(RoutePlanInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/routeplanservice/routePlan/quickestRoute").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RoutePlanController { @PostMapping(value = "/routePlan/minStopStations") public HttpEntity getMinStopStations(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers) { RoutePlanController.LOGGER.info("[Route Plan Service][Get Min Stop Stations] From: {} To: {} Num: {} Date: {}", info.getFormStationName(), info.getToStationName(), info.getNum(), info.getTravelDate()); return ok(routePlanService.searchMinStopStations(info, headers)); } @GetMapping(path = "/welcome") String home(); @PostMapping(value = "/routePlan/cheapestRoute") HttpEntity getCheapestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/quickestRoute") HttpEntity getQuickestRoutes(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value = "/routePlan/minStopStations") HttpEntity getMinStopStations(@RequestBody RoutePlanInfo info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetMinStopStations() throws Exception { RoutePlanInfo info = new RoutePlanInfo(); Mockito.when(routePlanService.searchMinStopStations(Mockito.any(RoutePlanInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/routeplanservice/routePlan/minStopStations").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AuthController { @GetMapping("/hello") public String getHello() { return "hello"; } @GetMapping("/hello") String getHello(); @PostMapping HttpEntity<Response> createDefaultUser(@RequestBody AuthDto authDto); }### Answer:
@Test public void testGetHello() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/auth/hello")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("hello")); } |
### Question:
AuthController { @PostMapping public HttpEntity<Response> createDefaultUser(@RequestBody AuthDto authDto) { userService.createDefaultAuthUser(authDto); Response response = new Response(1, "SUCCESS", authDto); return new ResponseEntity<>(response, HttpStatus.CREATED); } @GetMapping("/hello") String getHello(); @PostMapping HttpEntity<Response> createDefaultUser(@RequestBody AuthDto authDto); }### Answer:
@Test public void testCreateDefaultUser() throws Exception { AuthDto authDto = new AuthDto(); Mockito.when(userService.createDefaultAuthUser(Mockito.any(AuthDto.class))).thenReturn(null); String requestJson = JSONObject.toJSONString(authDto); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/auth").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals("SUCCESS", JSONObject.parseObject(result, Response.class).getMsg()); } |
### Question:
UserController { @GetMapping("/hello") public Object getHello() { return "Hello"; } @GetMapping("/hello") Object getHello(); @PostMapping("/login") ResponseEntity<Response> getToken(@RequestBody BasicAuthDto dao , @RequestHeader HttpHeaders headers); @GetMapping ResponseEntity<List<User>> getAllUser(@RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetHello() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/users/hello")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Hello")); } |
### Question:
UserController { @PostMapping("/login") public ResponseEntity<Response> getToken(@RequestBody BasicAuthDto dao , @RequestHeader HttpHeaders headers) { return ResponseEntity.ok(tokenService.getToken(dao, headers)); } @GetMapping("/hello") Object getHello(); @PostMapping("/login") ResponseEntity<Response> getToken(@RequestBody BasicAuthDto dao , @RequestHeader HttpHeaders headers); @GetMapping ResponseEntity<List<User>> getAllUser(@RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetToken() throws Exception { BasicAuthDto dao = new BasicAuthDto(); Mockito.when(tokenService.getToken(Mockito.any(BasicAuthDto.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(dao); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/users/login").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
StationServiceImpl implements StationService { @Override public Response delete(Station info, HttpHeaders headers) { if (repository.findById(info.getId()) != null) { Station station = new Station(info.getId(), info.getName()); repository.delete(station); return new Response<>(1, "Delete success", station); } return new Response<>(0, "Station not exist", null); } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testDelete1() { Station info = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(info); Mockito.doNothing().doThrow(new RuntimeException()).when(repository).delete(Mockito.any(Station.class)); Response result = stationServiceImpl.delete(info, headers); Assert.assertEquals("Delete success", result.getMsg()); }
@Test public void testDelete2() { Station info = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); Response result = stationServiceImpl.delete(info, headers); Assert.assertEquals(new Response<>(0, "Station not exist", null), result); } |
### Question:
UserController { @GetMapping public ResponseEntity<List<User>> getAllUser(@RequestHeader HttpHeaders headers) { return ResponseEntity.ok().body(userService.getAllUser(headers)); } @GetMapping("/hello") Object getHello(); @PostMapping("/login") ResponseEntity<Response> getToken(@RequestBody BasicAuthDto dao , @RequestHeader HttpHeaders headers); @GetMapping ResponseEntity<List<User>> getAllUser(@RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllUser() throws Exception { List<User> userList = new ArrayList<>(); Mockito.when(userService.getAllUser(Mockito.any(HttpHeaders.class))).thenReturn(userList); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/users")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(userList, JSONObject.parseObject(result, List.class)); } |
### Question:
UserController { @DeleteMapping("/{userId}") public ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers) { return ResponseEntity.ok(userService.deleteByUserId(UUID.fromString(userId), headers)); } @GetMapping("/hello") Object getHello(); @PostMapping("/login") ResponseEntity<Response> getToken(@RequestBody BasicAuthDto dao , @RequestHeader HttpHeaders headers); @GetMapping ResponseEntity<List<User>> getAllUser(@RequestHeader HttpHeaders headers); @DeleteMapping("/{userId}") ResponseEntity<Response> deleteUserById(@PathVariable String userId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteUserById() throws Exception { UUID userId = UUID.randomUUID(); Mockito.when(userService.deleteByUserId(Mockito.any(UUID.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/users/" + userId.toString())) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PriceServiceImpl implements PriceService { @Override public PriceConfig findById(String id, HttpHeaders headers) { PriceServiceImpl.LOGGER.info("[Price Service][Find By Id] ID: {}", id); return priceConfigRepository.findById(UUID.fromString(id)); } @Override Response createNewPriceConfig(PriceConfig createAndModifyPriceConfig, HttpHeaders headers); @Override PriceConfig findById(String id, HttpHeaders headers); @Override Response findByRouteIdAndTrainType(String routeId, String trainType, HttpHeaders headers); @Override Response findAllPriceConfig(HttpHeaders headers); @Override Response deletePriceConfig(PriceConfig c, HttpHeaders headers); @Override Response updatePriceConfig(PriceConfig c, HttpHeaders headers); }### Answer:
@Test public void testFindById() { Mockito.when(priceConfigRepository.findById(Mockito.any(UUID.class))).thenReturn(null); PriceConfig result = priceServiceImpl.findById(UUID.randomUUID().toString(), headers); Assert.assertNull(result); } |
### Question:
PriceServiceImpl implements PriceService { @Override public Response findByRouteIdAndTrainType(String routeId, String trainType, HttpHeaders headers) { PriceServiceImpl.LOGGER.info("[Price Service][Find By Route And Train Type] Rote: {} Train Type: {}", routeId, trainType); PriceConfig priceConfig = priceConfigRepository.findByRouteIdAndTrainType(routeId, trainType); PriceServiceImpl.LOGGER.info("[Price Service][Find By Route Id And Train Type]"); if (priceConfig == null) { return new Response<>(0, noThatConfig, null); } else { return new Response<>(1, "Success", priceConfig); } } @Override Response createNewPriceConfig(PriceConfig createAndModifyPriceConfig, HttpHeaders headers); @Override PriceConfig findById(String id, HttpHeaders headers); @Override Response findByRouteIdAndTrainType(String routeId, String trainType, HttpHeaders headers); @Override Response findAllPriceConfig(HttpHeaders headers); @Override Response deletePriceConfig(PriceConfig c, HttpHeaders headers); @Override Response updatePriceConfig(PriceConfig c, HttpHeaders headers); }### Answer:
@Test public void testFindByRouteIdAndTrainType1() { Mockito.when(priceConfigRepository.findByRouteIdAndTrainType(Mockito.anyString(), Mockito.anyString())).thenReturn(null); Response result = priceServiceImpl.findByRouteIdAndTrainType("route_id", "train_type", headers); Assert.assertEquals(new Response<>(0, "No that config", null), result); }
@Test public void testFindByRouteIdAndTrainType2() { PriceConfig priceConfig = new PriceConfig(); Mockito.when(priceConfigRepository.findByRouteIdAndTrainType(Mockito.anyString(), Mockito.anyString())).thenReturn(priceConfig); Response result = priceServiceImpl.findByRouteIdAndTrainType("route_id", "train_type", headers); Assert.assertEquals(new Response<>(1, "Success", priceConfig), result); } |
### Question:
PriceServiceImpl implements PriceService { @Override public Response findAllPriceConfig(HttpHeaders headers) { List<PriceConfig> list = priceConfigRepository.findAll(); if (list == null) { list = new ArrayList<>(); } if (!list.isEmpty()) { return new Response<>(1, "Success", list); } else { return new Response<>(0, "No price config", null); } } @Override Response createNewPriceConfig(PriceConfig createAndModifyPriceConfig, HttpHeaders headers); @Override PriceConfig findById(String id, HttpHeaders headers); @Override Response findByRouteIdAndTrainType(String routeId, String trainType, HttpHeaders headers); @Override Response findAllPriceConfig(HttpHeaders headers); @Override Response deletePriceConfig(PriceConfig c, HttpHeaders headers); @Override Response updatePriceConfig(PriceConfig c, HttpHeaders headers); }### Answer:
@Test public void testFindAllPriceConfig1() { Mockito.when(priceConfigRepository.findAll()).thenReturn(null); Response result = priceServiceImpl.findAllPriceConfig(headers); Assert.assertEquals(new Response<>(0, "No price config", null), result); }
@Test public void testFindAllPriceConfig2() { List<PriceConfig> list = new ArrayList<>(); list.add(new PriceConfig()); Mockito.when(priceConfigRepository.findAll()).thenReturn(list); Response result = priceServiceImpl.findAllPriceConfig(headers); Assert.assertEquals(new Response<>(1, "Success", list), result); } |
### Question:
PriceController { @GetMapping(path = "/prices/welcome") public String home() { return "Welcome to [ Price Service ] !"; } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/priceservice/prices/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Price Service ] !")); } |
### Question:
PriceController { @GetMapping(value = "/prices/{routeId}/{trainType}") public HttpEntity query(@PathVariable String routeId, @PathVariable String trainType, @RequestHeader HttpHeaders headers) { return ok(service.findByRouteIdAndTrainType(routeId, trainType, headers)); } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQuery() throws Exception { Mockito.when(service.findByRouteIdAndTrainType(Mockito.anyString(), Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/priceservice/prices/route_id/train_type")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PriceController { @GetMapping(value = "/prices") public HttpEntity queryAll(@RequestHeader HttpHeaders headers) { return ok(service.findAllPriceConfig(headers)); } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQueryAll() throws Exception { Mockito.when(service.findAllPriceConfig(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/priceservice/prices")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PriceController { @PostMapping(value = "/prices") public HttpEntity<?> create(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers) { return new ResponseEntity<>(service.createNewPriceConfig(info, headers), HttpStatus.CREATED); } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testCreate() throws Exception { PriceConfig info = new PriceConfig(); Mockito.when(service.createNewPriceConfig(Mockito.any(PriceConfig.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/priceservice/prices").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isCreated()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PriceController { @DeleteMapping(value = "/prices") public HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers) { return ok(service.deletePriceConfig(info, headers)); } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDelete() throws Exception { PriceConfig info = new PriceConfig(); Mockito.when(service.deletePriceConfig(Mockito.any(PriceConfig.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/priceservice/prices").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PriceController { @PutMapping(value = "/prices") public HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers) { return ok(service.updatePriceConfig(info, headers)); } @GetMapping(path = "/prices/welcome") String home(); @GetMapping(value = "/prices/{routeId}/{trainType}") HttpEntity query(@PathVariable String routeId, @PathVariable String trainType,
@RequestHeader HttpHeaders headers); @GetMapping(value = "/prices") HttpEntity queryAll(@RequestHeader HttpHeaders headers); @PostMapping(value = "/prices") HttpEntity<?> create(@RequestBody PriceConfig info,
@RequestHeader HttpHeaders headers); @DeleteMapping(value = "/prices") HttpEntity delete(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); @PutMapping(value = "/prices") HttpEntity update(@RequestBody PriceConfig info, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdate() throws Exception { PriceConfig info = new PriceConfig(); Mockito.when(service.updatePriceConfig(Mockito.any(PriceConfig.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/priceservice/prices").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
PreserveOtherServiceImpl implements PreserveOtherService { public Ticket dipatchSeat(Date date, String tripId, String startStationId, String endStataionId, int seatType, HttpHeaders httpHeaders) { Seat seatRequest = new Seat(); seatRequest.setTravelDate(date); seatRequest.setTrainNumber(tripId); seatRequest.setStartStation(startStationId); seatRequest.setSeatType(seatType); seatRequest.setDestStation(endStataionId); HttpEntity requestEntityTicket = new HttpEntity(seatRequest, httpHeaders); ResponseEntity<Response<Ticket>> reTicket = restTemplate.exchange( "http: HttpMethod.POST, requestEntityTicket, new ParameterizedTypeReference<Response<Ticket>>() { }); return reTicket.getBody().getData(); } @Override Response preserve(OrderTicketsInfo oti, HttpHeaders httpHeaders); Ticket dipatchSeat(Date date, String tripId, String startStationId, String endStataionId, int seatType, HttpHeaders httpHeaders); boolean sendEmail(NotifyInfo notifyInfo, HttpHeaders httpHeaders); User getAccount(String accountId, HttpHeaders httpHeaders); }### Answer:
@Test public void testDipatchSeat() { long mills = System.currentTimeMillis(); Seat seatRequest = new Seat(new Date(mills), "G1234", "start_station", "dest_station", 2); HttpEntity requestEntityTicket = new HttpEntity<>(seatRequest, headers); Response<Ticket> response = new Response<>(); ResponseEntity<Response<Ticket>> reTicket = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntityTicket, new ParameterizedTypeReference<Response<Ticket>>() { })).thenReturn(reTicket); Ticket result = preserveOtherServiceImpl.dipatchSeat(new Date(mills), "G1234", "start_station", "dest_station", 2, headers); Assert.assertNull(result); } |
### Question:
PreserveOtherServiceImpl implements PreserveOtherService { public boolean sendEmail(NotifyInfo notifyInfo, HttpHeaders httpHeaders) { PreserveOtherServiceImpl.LOGGER.info("[Preserve Service][Send Email]"); HttpEntity requestEntitySendEmail = new HttpEntity(notifyInfo, httpHeaders); ResponseEntity<Boolean> reSendEmail = restTemplate.exchange( "http: HttpMethod.POST, requestEntitySendEmail, Boolean.class); return reSendEmail.getBody(); } @Override Response preserve(OrderTicketsInfo oti, HttpHeaders httpHeaders); Ticket dipatchSeat(Date date, String tripId, String startStationId, String endStataionId, int seatType, HttpHeaders httpHeaders); boolean sendEmail(NotifyInfo notifyInfo, HttpHeaders httpHeaders); User getAccount(String accountId, HttpHeaders httpHeaders); }### Answer:
@Test public void testSendEmail() { NotifyInfo notifyInfo = new NotifyInfo(); HttpEntity requestEntitySendEmail = new HttpEntity<>(notifyInfo, headers); ResponseEntity<Boolean> reSendEmail = new ResponseEntity<>(true, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntitySendEmail, Boolean.class)).thenReturn(reSendEmail); boolean result = preserveOtherServiceImpl.sendEmail(notifyInfo, headers); Assert.assertTrue(result); } |
### Question:
PreserveOtherServiceImpl implements PreserveOtherService { public User getAccount(String accountId, HttpHeaders httpHeaders) { PreserveOtherServiceImpl.LOGGER.info("[Cancel Order Service][Get Order By Id]"); HttpEntity requestEntitySendEmail = new HttpEntity(httpHeaders); ResponseEntity<Response<User>> getAccount = restTemplate.exchange( "http: HttpMethod.GET, requestEntitySendEmail, new ParameterizedTypeReference<Response<User>>() { }); Response<User> result = getAccount.getBody(); return result.getData(); } @Override Response preserve(OrderTicketsInfo oti, HttpHeaders httpHeaders); Ticket dipatchSeat(Date date, String tripId, String startStationId, String endStataionId, int seatType, HttpHeaders httpHeaders); boolean sendEmail(NotifyInfo notifyInfo, HttpHeaders httpHeaders); User getAccount(String accountId, HttpHeaders httpHeaders); }### Answer:
@Test public void testGetAccount() { Response<User> response = new Response<>(); ResponseEntity<Response<User>> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, new ParameterizedTypeReference<Response<User>>() { })).thenReturn(re); User result = preserveOtherServiceImpl.getAccount("1", headers); Assert.assertNull(result); } |
### Question:
PreserveOtherController { @GetMapping(path = "/welcome") public String home() { return "Welcome to [ PreserveOther Service ] !"; } @GetMapping(path = "/welcome") String home(); @CrossOrigin(origins = "*") @PostMapping(value = "/preserveOther") HttpEntity preserve(@RequestBody OrderTicketsInfo oti,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/preserveotherservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ PreserveOther Service ] !")); } |
### Question:
PreserveOtherController { @CrossOrigin(origins = "*") @PostMapping(value = "/preserveOther") public HttpEntity preserve(@RequestBody OrderTicketsInfo oti, @RequestHeader HttpHeaders headers) { PreserveOtherController.LOGGER.info("[Preserve Other Service][Preserve] Account order from {} -----> {} at {}", oti.getFrom(), oti.getTo(), oti.getDate()); return ok(preserveService.preserve(oti, headers)); } @GetMapping(path = "/welcome") String home(); @CrossOrigin(origins = "*") @PostMapping(value = "/preserveOther") HttpEntity preserve(@RequestBody OrderTicketsInfo oti,
@RequestHeader HttpHeaders headers); }### Answer:
@Test public void testPreserve() throws Exception { OrderTicketsInfo oti = new OrderTicketsInfo(); Mockito.when(preserveService.preserve(Mockito.any(OrderTicketsInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(oti); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/preserveotherservice/preserveOther").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
StationServiceImpl implements StationService { @Override public Response query(HttpHeaders headers) { List<Station> stations = repository.findAll(); if (stations != null && !stations.isEmpty()) { return new Response<>(1, "Find all content", stations); } else { return new Response<>(0, "No content", null); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testQuery1() { List<Station> stations = new ArrayList<>(); stations.add(new Station()); Mockito.when(repository.findAll()).thenReturn(stations); Response result = stationServiceImpl.query(headers); Assert.assertEquals(new Response<>(1, "Find all content", stations), result); }
@Test public void testQuery2() { Mockito.when(repository.findAll()).thenReturn(null); Response result = stationServiceImpl.query(headers); Assert.assertEquals(new Response<>(0, "No content", null), result); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response getAllContacts(HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testGetAllContacts() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.getAllContacts(headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response deleteContact(String contactsId, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testDeleteContact() { Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.deleteContact("contactsId", headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response modifyContact(Contacts mci, HttpHeaders headers) { Response result; LOGGER.info("MODIFY CONTACTS: " + mci.toString()); HttpEntity requestEntity = new HttpEntity(mci, headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testModifyContact() { Contacts mci = new Contacts(); HttpEntity<Contacts> requestEntity = new HttpEntity<>(mci, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.modifyContact(mci, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response addContact(Contacts c, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(c, headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testAddContact() { Contacts c = new Contacts(); HttpEntity<Contacts> requestEntity = new HttpEntity<>(c, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.addContact(c, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response getAllStations(HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( stations, HttpMethod.GET, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testGetAllStations() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.getAllStations(headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response addStation(Station s, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(s, headers); ResponseEntity<Response> re = restTemplate.exchange( stations, HttpMethod.POST, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testAddStation() { Station s = new Station(); HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.addStation(s, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response deleteStation(Station s, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(s, headers); ResponseEntity<Response> re = restTemplate.exchange( stations, HttpMethod.DELETE, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testDeleteStation() { Station s = new Station(); HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.deleteStation(s, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response modifyStation(Station s, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(s, headers); ResponseEntity<Response> re = restTemplate.exchange( stations, HttpMethod.PUT, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testModifyStation() { Station s = new Station(); HttpEntity<Station> requestEntity = new HttpEntity<>(s, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.modifyStation(s, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response getAllTrains(HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( trains, HttpMethod.GET, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testGetAllTrains() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.getAllTrains(headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response addTrain(TrainType t, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(t, headers); ResponseEntity<Response> re = restTemplate.exchange( trains, HttpMethod.POST, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testAddTrain() { TrainType t = new TrainType(); HttpEntity<TrainType> requestEntity = new HttpEntity<>(t, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.addTrain(t, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response deleteTrain(String id, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testDeleteTrain() { Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.deleteTrain("id", headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response modifyTrain(TrainType t, HttpHeaders headers) { Response result; HttpEntity requestEntity = new HttpEntity(t, headers); ResponseEntity<Response> re = restTemplate.exchange( trains, HttpMethod.PUT, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testModifyTrain() { TrainType t = new TrainType(); HttpEntity<TrainType> requestEntity = new HttpEntity<>(t, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.modifyTrain(t, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response getAllConfigs(HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( configs, HttpMethod.GET, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testGetAllConfigs() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.getAllConfigs(headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response addConfig(Config c, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(c, headers); ResponseEntity<Response> re = restTemplate.exchange( configs, HttpMethod.POST, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testAddConfig() { Config c = new Config(); HttpEntity<Config> requestEntity = new HttpEntity<>(c, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.addConfig(c, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response deleteConfig(String name, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testDeleteConfig() { Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.deleteConfig("name", headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response modifyConfig(Config c, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(c, headers); ResponseEntity<Response> re = restTemplate.exchange( configs, HttpMethod.PUT, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testModifyConfig() { Config c = new Config(); HttpEntity<Config> requestEntity = new HttpEntity<>(c, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.modifyConfig(c, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response getAllPrices(HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( prices, HttpMethod.GET, requestEntity, Response.class); AdminBasicInfoServiceImpl.LOGGER.info("[!!!!GetAllPriceResult] "); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testGetAllPrices() { Mockito.when(restTemplate.exchange( "http: HttpMethod.GET, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.getAllPrices(headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response addPrice(PriceInfo pi, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(pi, headers); ResponseEntity<Response> re = restTemplate.exchange( prices, HttpMethod.POST, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testAddPrice() { PriceInfo pi = new PriceInfo(); HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.POST, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.addPrice(pi, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response deletePrice(PriceInfo pi, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(pi, headers); ResponseEntity<Response> re = restTemplate.exchange( prices, HttpMethod.DELETE, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testDeletePrice() { PriceInfo pi = new PriceInfo(); HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.deletePrice(pi, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
AdminBasicInfoServiceImpl implements AdminBasicInfoService { @Override public Response modifyPrice(PriceInfo pi, HttpHeaders headers) { HttpEntity requestEntity = new HttpEntity(pi, headers); ResponseEntity<Response> re = restTemplate.exchange( prices, HttpMethod.PUT, requestEntity, Response.class); return re.getBody(); } @Override Response getAllContacts(HttpHeaders headers); @Override Response deleteContact(String contactsId, HttpHeaders headers); @Override Response modifyContact(Contacts mci, HttpHeaders headers); @Override Response addContact(Contacts c, HttpHeaders headers); @Override Response getAllStations(HttpHeaders headers); @Override Response addStation(Station s, HttpHeaders headers); @Override Response deleteStation(Station s, HttpHeaders headers); @Override Response modifyStation(Station s, HttpHeaders headers); @Override Response getAllTrains(HttpHeaders headers); @Override Response addTrain(TrainType t, HttpHeaders headers); @Override Response deleteTrain(String id, HttpHeaders headers); @Override Response modifyTrain(TrainType t, HttpHeaders headers); @Override Response getAllConfigs(HttpHeaders headers); @Override Response addConfig(Config c, HttpHeaders headers); @Override Response deleteConfig(String name, HttpHeaders headers); @Override Response modifyConfig(Config c, HttpHeaders headers); @Override Response getAllPrices(HttpHeaders headers); @Override Response addPrice(PriceInfo pi, HttpHeaders headers); @Override Response deletePrice(PriceInfo pi, HttpHeaders headers); @Override Response modifyPrice(PriceInfo pi, HttpHeaders headers); }### Answer:
@Test public void testModifyPrice() { PriceInfo pi = new PriceInfo(); HttpEntity<PriceInfo> requestEntity = new HttpEntity<>(pi, headers); Mockito.when(restTemplate.exchange( "http: HttpMethod.PUT, requestEntity, Response.class)).thenReturn(re); response = adminBasicInfoService.modifyPrice(pi, headers); Assert.assertEquals(new Response<>(null, null, null), response); } |
### Question:
StationServiceImpl implements StationService { @Override public Response queryForId(String stationName, HttpHeaders headers) { Station station = repository.findByName(stationName); if (station != null) { return new Response<>(1, success, station.getId()); } else { return new Response<>(0, "Not exists", stationName); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testQueryForId1() { Station station = new Station(); Mockito.when(repository.findByName(Mockito.anyString())).thenReturn(station); Response result = stationServiceImpl.queryForId("station_name", headers); Assert.assertEquals(new Response<>(1, "Success", station.getId()), result); }
@Test public void testQueryForId2() { Mockito.when(repository.findByName(Mockito.anyString())).thenReturn(null); Response result = stationServiceImpl.queryForId("station_name", headers); Assert.assertEquals(new Response<>(0, "Not exists", "station_name"), result); } |
### Question:
StationServiceImpl implements StationService { @Override public Response queryForIdBatch(List<String> nameList, HttpHeaders headers) { ArrayList<String> result = new ArrayList<>(); for (int i = 0; i < nameList.size(); i++) { Station station = repository.findByName(nameList.get(i)); if (station == null) { result.add("Not Exist"); } else { result.add(station.getId()); } } if (!result.isEmpty()) { return new Response<>(1, success, result); } else { return new Response<>(0, "No content according to name list", null); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testQueryForIdBatch1() { List<String> nameList = new ArrayList<>(); Response result = stationServiceImpl.queryForIdBatch(nameList, headers); Assert.assertEquals(new Response<>(0, "No content according to name list", null), result); }
@Test public void testQueryForIdBatch2() { List<String> nameList = new ArrayList<>(); nameList.add("station_name"); Mockito.when(repository.findByName(Mockito.anyString())).thenReturn(null); Response result = stationServiceImpl.queryForIdBatch(nameList, headers); Assert.assertEquals("Success", result.getMsg()); } |
### Question:
StationServiceImpl implements StationService { @Override public Response queryById(String stationId, HttpHeaders headers) { Station station = repository.findById(stationId); if (station != null) { return new Response<>(1, success, station.getName()); } else { return new Response<>(0, "No that stationId", stationId); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testQueryById1() { Station station = new Station(); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(station); Response result = stationServiceImpl.queryById("station_id", headers); Assert.assertEquals(new Response<>(1, "Success", ""), result); }
@Test public void testQueryById2() { Mockito.when(repository.findById(Mockito.anyString())).thenReturn(null); Response result = stationServiceImpl.queryById("station_id", headers); Assert.assertEquals(new Response<>(0, "No that stationId", "station_id"), result); } |
### Question:
StationServiceImpl implements StationService { @Override public Response queryByIdBatch(List<String> idList, HttpHeaders headers) { ArrayList<String> result = new ArrayList<>(); for (int i = 0; i < idList.size(); i++) { Station station = repository.findById(idList.get(i)); if (station != null) { result.add(station.getName()); } } if (!result.isEmpty()) { return new Response<>(1, success, result); } else { return new Response<>(0, "No stationNamelist according to stationIdList", result); } } @Override Response create(Station station, HttpHeaders headers); @Override boolean exist(String stationName, HttpHeaders headers); @Override Response update(Station info, HttpHeaders headers); @Override Response delete(Station info, HttpHeaders headers); @Override Response query(HttpHeaders headers); @Override Response queryForId(String stationName, HttpHeaders headers); @Override Response queryForIdBatch(List<String> nameList, HttpHeaders headers); @Override Response queryById(String stationId, HttpHeaders headers); @Override Response queryByIdBatch(List<String> idList, HttpHeaders headers); }### Answer:
@Test public void testQueryByIdBatch1() { List<String> idList = new ArrayList<>(); Response result = stationServiceImpl.queryByIdBatch(idList, headers); Assert.assertEquals(new Response<>(0, "No stationNamelist according to stationIdList", new ArrayList<>()), result); }
@Test public void testQueryByIdBatch2() { Station station = new Station(); List<String> idList = new ArrayList<>(); idList.add("station_id"); Mockito.when(repository.findById(Mockito.anyString())).thenReturn(station); Response result = stationServiceImpl.queryByIdBatch(idList, headers); Assert.assertEquals("Success", result.getMsg()); } |
### Question:
StationController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ Station Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @GetMapping(value = "/stations") HttpEntity query(@RequestHeader HttpHeaders headers); @PostMapping(value = "/stations") ResponseEntity<Response> create(@RequestBody Station station, @RequestHeader HttpHeaders headers); @PutMapping(value = "/stations") HttpEntity update(@RequestBody Station station, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/stations") ResponseEntity<Response> delete(@RequestBody Station station, @RequestHeader HttpHeaders headers); @GetMapping(value = "/stations/id/{stationNameForId}") HttpEntity queryForStationId(@PathVariable(value = "stationNameForId")
String stationName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/stations/idlist") HttpEntity queryForIdBatch(@RequestBody List<String> stationNameList, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/stations/name/{stationIdForName}") HttpEntity queryById(@PathVariable(value = "stationIdForName")
String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/stations/namelist") HttpEntity queryForNameBatch(@RequestBody List<String> stationIdList, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/stationservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ Station Service ] !")); } |
### Question:
StationController { @GetMapping(value = "/stations") public HttpEntity query(@RequestHeader HttpHeaders headers) { return ok(stationService.query(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @GetMapping(value = "/stations") HttpEntity query(@RequestHeader HttpHeaders headers); @PostMapping(value = "/stations") ResponseEntity<Response> create(@RequestBody Station station, @RequestHeader HttpHeaders headers); @PutMapping(value = "/stations") HttpEntity update(@RequestBody Station station, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/stations") ResponseEntity<Response> delete(@RequestBody Station station, @RequestHeader HttpHeaders headers); @GetMapping(value = "/stations/id/{stationNameForId}") HttpEntity queryForStationId(@PathVariable(value = "stationNameForId")
String stationName, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/stations/idlist") HttpEntity queryForIdBatch(@RequestBody List<String> stationNameList, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(value = "/stations/name/{stationIdForName}") HttpEntity queryById(@PathVariable(value = "stationIdForName")
String stationId, @RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @PostMapping(value = "/stations/namelist") HttpEntity queryForNameBatch(@RequestBody List<String> stationIdList, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testQuery() throws Exception { Mockito.when(stationService.query(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/stationservice/stations")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
InsidePaymentServiceImpl implements InsidePaymentService { @Override public Response queryPayment(HttpHeaders headers) { List<Payment> payments = paymentRepository.findAll(); if (payments != null && !payments.isEmpty()) { return new Response<>(1, "Query Payment Success", payments); }else { return new Response<>(0, "Query Payment Failed", null); } } @Override Response pay(PaymentInfo info, HttpHeaders headers); @Override Response createAccount(AccountInfo info, HttpHeaders headers); @Override Response addMoney(String userId, String money, HttpHeaders headers); @Override Response queryAccount(HttpHeaders headers); String queryAccount(String userId, HttpHeaders headers); @Override Response queryPayment(HttpHeaders headers); @Override Response drawBack(String userId, String money, HttpHeaders headers); @Override Response payDifference(PaymentInfo info, HttpHeaders headers); @Override Response queryAddMoney(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); @Autowired
public AddMoneyRepository addMoneyRepository; @Autowired
public PaymentRepository paymentRepository; @Autowired
public RestTemplate restTemplate; }### Answer:
@Test public void testQueryPayment1() { List<Payment> payments = new ArrayList<>(); payments.add(new Payment()); Mockito.when(paymentRepository.findAll()).thenReturn(payments); Response result = insidePaymentServiceImpl.queryPayment(headers); Assert.assertEquals(new Response<>(1, "Query Payment Success", payments), result); }
@Test public void testQueryPayment2() { Mockito.when(paymentRepository.findAll()).thenReturn(null); Response result = insidePaymentServiceImpl.queryPayment(headers); Assert.assertEquals(new Response<>(0, "Query Payment Failed", null), result); } |
### Question:
TravelPlanController { @GetMapping(path = "/welcome" ) public String home() { return "Welcome to [ TravelPlan Service ] !"; } @GetMapping(path = "/welcome" ) String home(); @PostMapping(value="/travelPlan/transferResult" ) HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/cheapest") HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/quickest") HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/minStation") HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/travelplanservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ TravelPlan Service ] !")); } |
### Question:
TravelPlanController { @PostMapping(value="/travelPlan/transferResult" ) public HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers) { TravelPlanController.LOGGER.info("[Search Transit]"); return ok(travelPlanService.getTransferSearch(info, headers)); } @GetMapping(path = "/welcome" ) String home(); @PostMapping(value="/travelPlan/transferResult" ) HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/cheapest") HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/quickest") HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/minStation") HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetTransferResult() throws Exception { TransferTravelInfo info = new TransferTravelInfo(); Mockito.when(travelPlanService.getTransferSearch(Mockito.any(TransferTravelInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(info); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/travelplanservice/travelPlan/transferResult").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TravelPlanController { @PostMapping(value="/travelPlan/cheapest") public HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers) { TravelPlanController.LOGGER.info("[Search Cheapest]"); return ok(travelPlanService.getCheapest(queryInfo, headers)); } @GetMapping(path = "/welcome" ) String home(); @PostMapping(value="/travelPlan/transferResult" ) HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/cheapest") HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/quickest") HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/minStation") HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetByCheapest() throws Exception { TripInfo queryInfo = new TripInfo(); Mockito.when(travelPlanService.getCheapest(Mockito.any(TripInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(queryInfo); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/travelplanservice/travelPlan/cheapest").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TravelPlanController { @PostMapping(value="/travelPlan/quickest") public HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers) { TravelPlanController.LOGGER.info("[Search Quickest]"); return ok(travelPlanService.getQuickest(queryInfo, headers)); } @GetMapping(path = "/welcome" ) String home(); @PostMapping(value="/travelPlan/transferResult" ) HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/cheapest") HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/quickest") HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/minStation") HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetByQuickest() throws Exception { TripInfo queryInfo = new TripInfo(); Mockito.when(travelPlanService.getQuickest(Mockito.any(TripInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(queryInfo); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/travelplanservice/travelPlan/quickest").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
TravelPlanController { @PostMapping(value="/travelPlan/minStation") public HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers) { TravelPlanController.LOGGER.info("[Search Min Station]"); return ok(travelPlanService.getMinStation(queryInfo, headers)); } @GetMapping(path = "/welcome" ) String home(); @PostMapping(value="/travelPlan/transferResult" ) HttpEntity getTransferResult(@RequestBody TransferTravelInfo info, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/cheapest") HttpEntity getByCheapest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/quickest") HttpEntity getByQuickest(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); @PostMapping(value="/travelPlan/minStation") HttpEntity getByMinStation(@RequestBody TripInfo queryInfo, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetByMinStation() throws Exception { TripInfo queryInfo = new TripInfo(); Mockito.when(travelPlanService.getMinStation(Mockito.any(TripInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(queryInfo); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/travelplanservice/travelPlan/minStation").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminTravelServiceImpl implements AdminTravelService { @Override public Response deleteTravel(String tripId, HttpHeaders headers) { Response result; String requestUtl = ""; if (tripId.charAt(0) == 'G' || tripId.charAt(0) == 'D') { requestUtl = "http: } else { requestUtl = "http: } HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( requestUtl, HttpMethod.DELETE, requestEntity, Response.class); result = re.getBody(); return result; } @Override Response getAllTravels(HttpHeaders headers); @Override Response addTravel(TravelInfo request, HttpHeaders headers); @Override Response updateTravel(TravelInfo request, HttpHeaders headers); @Override Response deleteTravel(String tripId, HttpHeaders headers); }### Answer:
@Test public void testDeleteTravel1() { Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.deleteTravel("GaoTie", headers); Assert.assertEquals(new Response<>(null, null, null), result); }
@Test public void testDeleteTravel2() { Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminTravelServiceImpl.deleteTravel("K1024", headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminTravelController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ AdminTravel Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") HttpEntity getAllTravels(@RequestHeader HttpHeaders headers); @PostMapping(value = "/admintravel") HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/admintravel") HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/admintravel/{tripId}") HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/admintravelservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ AdminTravel Service ] !")); } |
### Question:
AdminTravelController { @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") public HttpEntity getAllTravels(@RequestHeader HttpHeaders headers) { return ok(adminTravelService.getAllTravels(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") HttpEntity getAllTravels(@RequestHeader HttpHeaders headers); @PostMapping(value = "/admintravel") HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/admintravel") HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/admintravel/{tripId}") HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllTravels() throws Exception { Mockito.when(adminTravelService.getAllTravels(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/admintravelservice/admintravel")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminTravelController { @PostMapping(value = "/admintravel") public HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers) { return ok(adminTravelService.addTravel(request, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") HttpEntity getAllTravels(@RequestHeader HttpHeaders headers); @PostMapping(value = "/admintravel") HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/admintravel") HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/admintravel/{tripId}") HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testAddTravel() throws Exception { TravelInfo request = new TravelInfo(); Mockito.when(adminTravelService.addTravel(Mockito.any(TravelInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(request); String result = mockMvc.perform(MockMvcRequestBuilders.post("/api/v1/admintravelservice/admintravel").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminTravelController { @PutMapping(value = "/admintravel") public HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers) { return ok(adminTravelService.updateTravel(request, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") HttpEntity getAllTravels(@RequestHeader HttpHeaders headers); @PostMapping(value = "/admintravel") HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/admintravel") HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/admintravel/{tripId}") HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testUpdateTravel() throws Exception { TravelInfo request = new TravelInfo(); Mockito.when(adminTravelService.updateTravel(Mockito.any(TravelInfo.class), Mockito.any(HttpHeaders.class))).thenReturn(response); String requestJson = JSONObject.toJSONString(request); String result = mockMvc.perform(MockMvcRequestBuilders.put("/api/v1/admintravelservice/admintravel").contentType(MediaType.APPLICATION_JSON).content(requestJson)) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
AdminTravelController { @DeleteMapping(value = "/admintravel/{tripId}") public HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers) { return ok(adminTravelService.deleteTravel(tripId, headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/admintravel") HttpEntity getAllTravels(@RequestHeader HttpHeaders headers); @PostMapping(value = "/admintravel") HttpEntity addTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/admintravel") HttpEntity updateTravel(@RequestBody TravelInfo request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/admintravel/{tripId}") HttpEntity deleteTravel(@PathVariable String tripId, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testDeleteTravel() throws Exception { Mockito.when(adminTravelService.deleteTravel(Mockito.anyString(), Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.delete("/api/v1/admintravelservice/admintravel/trip_id")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
InsidePaymentServiceImpl implements InsidePaymentService { @Override public Response drawBack(String userId, String money, HttpHeaders headers) { if (addMoneyRepository.findByUserId(userId) != null) { Money addMoney = new Money(); addMoney.setUserId(userId); addMoney.setMoney(money); addMoney.setType(MoneyType.D); addMoneyRepository.save(addMoney); return new Response<>(1, "Draw Back Money Success", null); } else { return new Response<>(0, "Draw Back Money Failed", null); } } @Override Response pay(PaymentInfo info, HttpHeaders headers); @Override Response createAccount(AccountInfo info, HttpHeaders headers); @Override Response addMoney(String userId, String money, HttpHeaders headers); @Override Response queryAccount(HttpHeaders headers); String queryAccount(String userId, HttpHeaders headers); @Override Response queryPayment(HttpHeaders headers); @Override Response drawBack(String userId, String money, HttpHeaders headers); @Override Response payDifference(PaymentInfo info, HttpHeaders headers); @Override Response queryAddMoney(HttpHeaders headers); @Override void initPayment(Payment payment, HttpHeaders headers); @Autowired
public AddMoneyRepository addMoneyRepository; @Autowired
public PaymentRepository paymentRepository; @Autowired
public RestTemplate restTemplate; }### Answer:
@Test public void testDrawBack1() { List<Money> list = new ArrayList<>(); Mockito.when(addMoneyRepository.findByUserId(Mockito.anyString())).thenReturn(list); Mockito.when(addMoneyRepository.save(Mockito.any(Money.class))).thenReturn(null); Response result = insidePaymentServiceImpl.drawBack("user_id", "money", headers); Assert.assertEquals(new Response<>(1, "Draw Back Money Success", null), result); }
@Test public void testDrawBack2() { Mockito.when(addMoneyRepository.findByUserId(Mockito.anyString())).thenReturn(null); Response result = insidePaymentServiceImpl.drawBack("user_id", "money", headers); Assert.assertEquals(new Response<>(0, "Draw Back Money Failed", null), result); } |
### Question:
AdminOrderServiceImpl implements AdminOrderService { @Override public Response deleteOrder(String orderId, String trainNumber, HttpHeaders headers) { Response deleteOrderResult; if (trainNumber.startsWith("G") || trainNumber.startsWith("D")) { AdminOrderServiceImpl.LOGGER.info("[Admin Order Service][Delete Order]"); HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); deleteOrderResult = re.getBody(); } else { AdminOrderServiceImpl.LOGGER.info("[Admin Order Service][Delete Order Other]"); HttpEntity requestEntity = new HttpEntity(headers); ResponseEntity<Response> re = restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class); deleteOrderResult = re.getBody(); } return deleteOrderResult; } @Override Response getAllOrders(HttpHeaders headers); @Override Response deleteOrder(String orderId, String trainNumber, HttpHeaders headers); @Override Response updateOrder(Order request, HttpHeaders headers); @Override Response addOrder(Order request, HttpHeaders headers); }### Answer:
@Test public void testDeleteOrder1() { Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminOrderService.deleteOrder("orderId", "G", headers); Assert.assertEquals(new Response<>(null, null, null), result); }
@Test public void testDeleteOrder2() { Response response = new Response(); ResponseEntity<Response> re = new ResponseEntity<>(response, HttpStatus.OK); Mockito.when(restTemplate.exchange( "http: HttpMethod.DELETE, requestEntity, Response.class)).thenReturn(re); Response result = adminOrderService.deleteOrder("orderId", "K", headers); Assert.assertEquals(new Response<>(null, null, null), result); } |
### Question:
AdminOrderController { @GetMapping(path = "/welcome") public String home(@RequestHeader HttpHeaders headers) { return "Welcome to [ AdminOrder Service ] !"; } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminorder") HttpEntity getAllOrders(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminorder") HttpEntity addOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/adminorder") HttpEntity updateOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminorder/{orderId}/{trainNumber}") HttpEntity deleteOrder(@PathVariable String orderId, @PathVariable String trainNumber, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testHome() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminorderservice/welcome")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Welcome to [ AdminOrder Service ] !")); } |
### Question:
AdminOrderController { @CrossOrigin(origins = "*") @GetMapping(path = "/adminorder") public HttpEntity getAllOrders(@RequestHeader HttpHeaders headers) { return ok(adminOrderService.getAllOrders(headers)); } @GetMapping(path = "/welcome") String home(@RequestHeader HttpHeaders headers); @CrossOrigin(origins = "*") @GetMapping(path = "/adminorder") HttpEntity getAllOrders(@RequestHeader HttpHeaders headers); @PostMapping(value = "/adminorder") HttpEntity addOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers); @PutMapping(value = "/adminorder") HttpEntity updateOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers); @DeleteMapping(value = "/adminorder/{orderId}/{trainNumber}") HttpEntity deleteOrder(@PathVariable String orderId, @PathVariable String trainNumber, @RequestHeader HttpHeaders headers); }### Answer:
@Test public void testGetAllOrders() throws Exception { Mockito.when(adminOrderService.getAllOrders(Mockito.any(HttpHeaders.class))).thenReturn(response); String result = mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/adminorderservice/adminorder")) .andExpect(MockMvcResultMatchers.status().isOk()) .andReturn().getResponse().getContentAsString(); Assert.assertEquals(response, JSONObject.parseObject(result, Response.class)); } |
### Question:
RegionSupport { public String getRegion(@XPath(value = "/order:order/order:customer/order:country", namespaces = @NamespacePrefix(prefix = "order", uri = "http: if (country.equals("AU")) { return APAC; } else if (country.equals("US")) { return AMER; } else { return EMEA; } } String getRegion(@XPath(value = "/order:order/order:customer/order:country",
namespaces = @NamespacePrefix(prefix = "order", uri = "http://fabric8.com/examples/order/v7")) String country); static final String AMER; static final String APAC; static final String EMEA; }### Answer:
@Test public void testGetRegion() { assertEquals(APAC, support.getRegion("AU")); assertEquals(EMEA, support.getRegion("BE")); assertEquals(EMEA, support.getRegion("UK")); assertEquals(AMER, support.getRegion("US")); } |
### Question:
OrderService { public void validateOrderDate( @XPath(value = "/order:order/order:date", namespaces = @NamespacePrefix(prefix = "order", uri = "http: final Calendar calendar = new GregorianCalendar(); try { calendar.setTime(DATE_FORMAT.parse(date)); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { LOGGER.warn("Order validation failure: order date " + date + " should not be a Sunday"); throw new OrderValidationException("Order date should not be a Sunday: " + date); } } catch (ParseException e) { throw new OrderValidationException("Invalid order date: " + date); } } void validateOrderDate(
@XPath(value = "/order:order/order:date",
namespaces = @NamespacePrefix(prefix = "order", uri = "http://fabric8.com/examples/order/v7")) String date); void randomlyThrowRuntimeException(@Header(Exchange.FILE_NAME) String name); }### Answer:
@Test public void testValidateValidOrderDate() { try { service.validateOrderDate("2012-03-01"); service.validateOrderDate("2012-03-02"); service.validateOrderDate("2012-03-03"); service.validateOrderDate("2012-03-05"); } catch (OrderValidationException e) { fail("No OrderValidationException expected - we can accept orders on any of those dates"); } }
@Test(expected = OrderValidationException.class) public void testValidateInvalidOrderDate() throws OrderValidationException { service.validateOrderDate("2012-03-04"); } |
### Question:
ResourceRegistrar { public static XAResourceProducer get(final String uniqueName) { if (uniqueName != null) { for (ProducerHolder holder : resources) { if (!holder.isInitialized()) continue; if (uniqueName.equals(holder.getUniqueName())) return holder.producer; } } return null; } private ResourceRegistrar(); static XAResourceProducer get(final String uniqueName); static Set<String> getResourcesUniqueNames(); static void register(XAResourceProducer producer); static void unregister(XAResourceProducer producer); static XAResourceHolder findXAResourceHolder(XAResource xaResource); final static Charset UNIQUE_NAME_CHARSET; }### Answer:
@Test public void testGet() throws Exception { assertSame(producer, ResourceRegistrar.get("xa-rp")); assertNull(ResourceRegistrar.get("non-existing")); assertNull(ResourceRegistrar.get(null)); }
@Test public void testGetDoesNotReturnUninitializedProducers() throws Exception { CountDownLatch border = new CountDownLatch(1); Future future = registerBlockingProducer(createMockProducer("uninitialized"), border); assertNull(ResourceRegistrar.get("uninitialized")); border.countDown(); future.get(); assertNotNull(ResourceRegistrar.get("uninitialized")); } |
### Question:
ResourceRegistrar { public static Set<String> getResourcesUniqueNames() { final Set<String> names = new HashSet<String>(resources.size()); for (ProducerHolder holder : resources) { if (!holder.isInitialized()) continue; names.add(holder.getUniqueName()); } return Collections.unmodifiableSet(names); } private ResourceRegistrar(); static XAResourceProducer get(final String uniqueName); static Set<String> getResourcesUniqueNames(); static void register(XAResourceProducer producer); static void unregister(XAResourceProducer producer); static XAResourceHolder findXAResourceHolder(XAResource xaResource); final static Charset UNIQUE_NAME_CHARSET; }### Answer:
@Test public void testGetResourcesUniqueNames() throws Exception { assertArrayEquals(new Object[]{"xa-rp"}, ResourceRegistrar.getResourcesUniqueNames().toArray()); } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.