/** * 单元测试 - 更新菜品信息 * * @throws DishNotFoundException * @throws CategoryNotFoundException * @throws DuplicateNameException */ @Test public void updateDishTest() throws DishNotFoundException, CategoryNotFoundException, DuplicateNameException { Dish dish = dishService.getDishById(1L); DishVO dishVO = new DishVO(); dishVO.setId(dish.getId()); dishVO.setCategoryId(dish.getCategory().getId()); dishVO.setMisc(dish.getMisc()); dishVO.setName(dish.getName()); dishVO.setPicPath(dish.getPicPath()); dishVO.setPrice(dish.getPrice()); dishService.updateDish(dishVO); }
/** * 单元测试 - 使用错误的菜品分类信息更新菜品 * * @throws DishNotFoundException */ @Test public void updateDishWithInvalidCategoryTest() throws DishNotFoundException { Dish dish = dishService.getDishById(1L); DishVO dishVO = new DishVO(); dishVO.setId(dish.getId()); dishVO.setCategoryId(1000L); dishVO.setMisc(dish.getMisc()); dishVO.setName(dish.getName()); dishVO.setPicPath(dish.getPicPath()); dishVO.setPrice(dish.getPrice()); try { dishService.updateDish(dishVO); } catch (Exception exception) { assertEquals(exception.getClass(), CategoryNotFoundException.class); } }
/** * 根据菜品ID查找菜品 * * @param dishId 菜品ID * @return 菜品实体 */ @GET @Path("/{dishId}") @Scope("request") @Produces(MediaType.APPLICATION_JSON) public Map<String, DishVO> getDishById(@PathParam("dishId") Integer dishId) { logger.info("[REST_CALL= getDishById, dishId=" + dishId + "]"); Dish dish = dishService.getDishById(dishId); DishVO dishVO = new DishVO(); if (null != dish) { dishVO.setId(dish.getId()); dishVO.setName(dish.getName()); dishVO.setPicPath(dish.getPicPath()); dishVO.setPrice(dish.getPrice()); dishVO.setOnSell(dish.isOnSell()); } Map<String, DishVO> result = new HashMap<String, DishVO>(); result.put("dish", dishVO); return result; }
/** 单元测试 - 通过正确的菜品ID获取菜品 */ @Test public void getDishByIdTest() throws DishNotFoundException { Dish dish = dishService.getDishById(1L); assertEquals(dish.getName(), "手撕包菜"); }