Beispiel #1
0
  @Test
  public void testPost() {
    // invalid request
    Response response = service.post(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.post(new RequestBean<MenuItemBean>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.post(new RequestBean<MenuItemBean>(null, new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.post(new RequestBean<MenuItemBean>(new CredentialsBean(), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.post(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, bad menu item data
    response =
        service.post(
            new RequestBean<MenuItemBean>(
                new CredentialsBean("manager", "password"), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    MenuItemBean menuItem =
        new MenuItemBean(0L, "name", "description", 12.45, MenuItemCategory.SIDE);
    response =
        service.post(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), menuItem));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    MenuItemBean createdMenuItem = (MenuItemBean) response.getEntity();
    assertNotNull(createdMenuItem);
  }
Beispiel #2
0
  @Test
  public void testUpdate() {
    // invalid request
    Response response = service.post(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.update(new RequestBean<MenuItemBean>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.update(new RequestBean<MenuItemBean>(null, new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.update(new RequestBean<MenuItemBean>(new CredentialsBean(), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.update(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, bad menu item data
    response =
        service.update(
            new RequestBean<MenuItemBean>(
                new CredentialsBean("manager", "password"), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    MenuItemBean oldMenuItem =
        new MenuItemBean(1L, "updated name", "updated description", 12.45, MenuItemCategory.SIDE);
    response =
        service.update(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), oldMenuItem));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    Boolean updated = (Boolean) response.getEntity();
    assertNotNull(updated);
    assertTrue(updated);

    MenuItemBean updatedMenuItem =
        (MenuItemBean)
            service
                .get(new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(1)))
                .getEntity();
    assertNotNull(updatedMenuItem);

    assertEquals(oldMenuItem.getId(), updatedMenuItem.getId());
    assertEquals(oldMenuItem.getName(), updatedMenuItem.getName());
    assertEquals(oldMenuItem.getDescription(), updatedMenuItem.getDescription());
    assertEquals(0, Double.compare(oldMenuItem.getPrice(), updatedMenuItem.getPrice()));
    assertEquals(oldMenuItem.getItemCategory(), updatedMenuItem.getItemCategory());
  }