示例#1
0
  /**
   * 单元测试 - 更新菜品信息
   *
   * @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);
  }
示例#2
0
  /**
   * 单元测试 - 添加菜品信息
   *
   * @throws CategoryNotFoundException
   * @throws DuplicateNameException
   */
  @Test
  public void addDishTest() throws DuplicateNameException, CategoryNotFoundException {
    DishVO dishVO = new DishVO();

    dishVO.setCategoryId(1L);
    dishVO.setMisc("misc");
    dishVO.setName("手撕包菜1");
    dishVO.setPrice(150.0f);
    dishVO.setPicPath("");

    Dish dish = dishService.addDish(dishVO);

    assertNotNull(dish);
    assertTrue(dish.getId() > 0L);
  }
示例#3
0
  /**
   * 单元测试 - 使用错误的菜品分类信息更新菜品
   *
   * @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);
    }
  }
示例#4
0
  /**
   * 单元测试 - 使用已存在的菜品名更新菜品
   *
   * @throws DishNotFoundException
   */
  @Test
  public void updateDishWithDuplicateNameTest() throws DishNotFoundException {
    String duplicateName = "无油版左公鸡";
    Dish dish = dishService.getDishById(1L);
    DishVO dishVO = new DishVO();

    dishVO.setId(dish.getId());
    dishVO.setCategoryId(dish.getCategory().getId());
    dishVO.setMisc(dish.getMisc());
    dishVO.setName(duplicateName);
    dishVO.setPicPath(dish.getPicPath());
    dishVO.setPrice(dish.getPrice());

    try {
      dishService.updateDish(dishVO);
    } catch (Exception exception) {
      assertEquals(exception.getClass(), DuplicateNameException.class);
    }
  }
示例#5
0
  /**
   * 根据菜品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;
  }