/*
  * Update the task with necessary information when the task is success.
  */
 private void updateSuccessTask(Task task, String vdc, String chefClientname) {
   String piResource =
       MessageFormat.format(
           propertiesProvider.getProperty(CHEF_NODE_BASE_URL), vdc, chefClientname); // the product
   task.setResult(new TaskReference(piResource));
   task.setEndTime(new Date());
   task.setStatus(TaskStates.SUCCESS);
   taskManager.updateTask(task);
 }
 /*
  * Update the task with necessary information when the task is wrong.
  */
 private void updateErrorTask(Task task, String message, Throwable t) {
   TaskError error = new TaskError(message);
   error.setMajorErrorCode(t.getMessage());
   error.setMinorErrorCode(t.getClass().getSimpleName());
   task.setEndTime(new Date());
   task.setStatus(TaskStates.ERROR);
   task.setError(error);
   taskManager.updateTask(task);
   LOGGER.info(
       "An error occurs while deleting a node fromChef Server. See task "
           + task.getHref()
           + "for more information");
 }
 /*
  * Update the task with necessary information when the task is wrong and the product instance exists in the system.
  */
 private void updateErrorTask(
     String vdc, String chefClientname, Task task, String message, Throwable t) {
   String piResource =
       MessageFormat.format(
           propertiesProvider.getProperty(CHEF_NODE_BASE_URL), vdc, chefClientname); // the product
   task.setResult(new TaskReference(piResource));
   updateErrorTask(task, message, t);
 }
  @Test
  public void shouldUpdateErrorTaskWhenDeleteAndChefClientExecutionError()
      throws ChefClientExecutionException {
    // given
    String vdc = "virtualDataCenter";
    String chefClientName = "chefClientNames";
    Task task = new Task();
    String callback = "http://callback";

    // when
    when(propertiesProvider.getProperty(SystemPropertiesProvider.CHEF_NODE_BASE_URL))
        .thenReturn("http://baseurl");
    doThrow(new ChefClientExecutionException("error"))
        .when(chefCientManager)
        .chefClientDelete(vdc, chefClientName);
    chefClientAsyncManager.chefClientDelete(vdc, chefClientName, task, callback);

    // then
    assertEquals(task.getStatus(), Task.TaskStates.ERROR);
    verify(chefCientManager).chefClientDelete(vdc, chefClientName);
    verify(taskManager).updateTask(task);
  }