コード例 #1
0
  @Test
  public void should_open_action_plan() {
    when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class)))
        .thenReturn(DefaultActionPlan.create("Long term"));

    Result result = service.openActionPlan("ABCD");
    verify(actionPlanService).setStatus(eq("ABCD"), eq("OPEN"), any(UserSession.class));
    assertThat(result.ok()).isTrue();
  }
コード例 #2
0
  @VisibleForTesting
  Result<ActionPlan> createActionPlanResult(
      Map<String, String> parameters, @Nullable DefaultActionPlan existingActionPlan) {
    Result<ActionPlan> result = Result.of();

    String name = parameters.get(NAME_PARAM);
    String description = parameters.get(DESCRIPTION_PARAM);
    String deadLineParam = parameters.get("deadLine");
    String projectParam = parameters.get(PROJECT_PARAM);

    checkMandatorySizeParameter(name, NAME_PARAM, 200, result);
    checkOptionalSizeParameter(description, DESCRIPTION_PARAM, 1000, result);

    // Can only set project on creation
    if (existingActionPlan == null) {
      checkProject(projectParam, result);
    }
    Date deadLine = checkAndReturnDeadline(deadLineParam, result);

    // TODO move this check in the service, on creation and update
    if (!Strings.isNullOrEmpty(projectParam)
        && !Strings.isNullOrEmpty(name)
        && isActionPlanNameAvailable(existingActionPlan, name, projectParam)) {
      result.addError(Result.Message.ofL10n("action_plans.same_name_in_same_project"));
    }

    if (result.ok()) {
      DefaultActionPlan actionPlan =
          DefaultActionPlan.create(name)
              .setDescription(description)
              .setUserLogin(UserSession.get().login())
              .setDeadLine(deadLine);

      // Can only set project on creation
      if (existingActionPlan == null) {
        actionPlan.setProjectKey(projectParam);
      } else {
        actionPlan.setProjectKey(existingActionPlan.projectKey());
      }

      result.set(actionPlan);
    }
    return result;
  }
コード例 #3
0
ファイル: ActionPlanDto.java プロジェクト: Eischer/sonar
 public DefaultActionPlan toActionPlan() {
   return DefaultActionPlan.create(name)
       .setKey(kee)
       .setProjectKey(projectKey)
       .setDescription(description)
       .setStatus(status)
       .setDeadLine(deadLine)
       .setUserLogin(userLogin)
       .setCreatedAt(createdAt)
       .setUpdatedAt(updatedAt);
 }
コード例 #4
0
  @Test
  public void should_get_error_on_action_plan_result_when_name_is_already_used_for_project() {
    Map<String, String> parameters = newHashMap();
    parameters.put("name", "Long term");
    parameters.put("description", "Long term issues");
    parameters.put("project", "org.sonar.Sample");

    when(actionPlanService.isNameAlreadyUsedForProject(anyString(), anyString())).thenReturn(true);

    Result result =
        service.createActionPlanResult(parameters, DefaultActionPlan.create("Short term"));
    assertThat(result.ok()).isFalse();
    assertThat(result.errors())
        .contains(Result.Message.ofL10n("action_plans.same_name_in_same_project"));
  }
コード例 #5
0
  @Test
  public void should_update_action_plan() {
    when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class)))
        .thenReturn(DefaultActionPlan.create("Long term"));

    Map<String, String> parameters = newHashMap();
    parameters.put("name", "New Long term");
    parameters.put("description", "New Long term issues");
    parameters.put("deadLine", "2113-05-13");
    parameters.put("project", "org.sonar.MultiSample");

    ArgumentCaptor<ActionPlan> actionPlanCaptor = ArgumentCaptor.forClass(ActionPlan.class);
    Result result = service.updateActionPlan("ABCD", parameters);
    assertThat(result.ok()).isTrue();

    verify(actionPlanService).update(actionPlanCaptor.capture(), any(UserSession.class));
    ActionPlan actionPlan = actionPlanCaptor.getValue();

    assertThat(actionPlan).isNotNull();
    assertThat(actionPlan.key()).isNotNull();
    assertThat(actionPlan.name()).isEqualTo("New Long term");
    assertThat(actionPlan.description()).isEqualTo("New Long term issues");
    assertThat(actionPlan.deadLine()).isNotNull();
  }
コード例 #6
0
 public Result<ActionPlan> updateActionPlan(String key, Map<String, String> parameters) {
   DefaultActionPlan existingActionPlan =
       (DefaultActionPlan) actionPlanService.findByKey(key, UserSession.get());
   if (existingActionPlan == null) {
     Result<ActionPlan> result = Result.of();
     result.addError(
         Result.Message.ofL10n(ACTION_PLANS_ERRORS_ACTION_PLAN_DOES_NOT_EXIST_MESSAGE, key));
     return result;
   } else {
     Result<ActionPlan> result = createActionPlanResult(parameters, existingActionPlan);
     if (result.ok()) {
       DefaultActionPlan actionPlan = (DefaultActionPlan) result.get();
       actionPlan.setKey(existingActionPlan.key());
       actionPlan.setUserLogin(existingActionPlan.userLogin());
       result.set(actionPlanService.update(actionPlan, UserSession.get()));
     }
     return result;
   }
 }
コード例 #7
0
 private boolean isActionPlanNameAvailable(
     @Nullable DefaultActionPlan existingActionPlan, String name, String projectParam) {
   return (existingActionPlan == null || !name.equals(existingActionPlan.name()))
       && actionPlanService.isNameAlreadyUsedForProject(name, projectParam);
 }