コード例 #1
0
 public Result<ActionPlan> createActionPlan(Map<String, String> parameters) {
   Result<ActionPlan> result = createActionPlanResult(parameters);
   if (result.ok()) {
     result.set(actionPlanService.create(result.get(), UserSession.get()));
   }
   return result;
 }
コード例 #2
0
 public Result<ActionPlan> deleteActionPlan(String actionPlanKey) {
   Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
   if (result.ok()) {
     actionPlanService.delete(actionPlanKey, UserSession.get());
   }
   return result;
 }
コード例 #3
0
 public Result<ActionPlan> openActionPlan(String actionPlanKey) {
   Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
   if (result.ok()) {
     result.set(
         actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN, UserSession.get()));
   }
   return result;
 }
コード例 #4
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();
  }
コード例 #5
0
  @Test
  public void should_not_update_action_plan_when_action_plan_is_not_found() {
    when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(null);

    Result result = service.updateActionPlan("ABCD", null);
    assertThat(result.ok()).isFalse();
    assertThat(result.errors())
        .contains(Result.Message.ofL10n("action_plans.errors.action_plan_does_not_exist", "ABCD"));
  }
コード例 #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
  @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"));
  }
コード例 #8
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();
  }
コード例 #9
0
 private boolean isActionPlanNameAvailable(
     @Nullable DefaultActionPlan existingActionPlan, String name, String projectParam) {
   return (existingActionPlan == null || !name.equals(existingActionPlan.name()))
       && actionPlanService.isNameAlreadyUsedForProject(name, projectParam);
 }
コード例 #10
0
 public List<ActionPlanStats> findActionPlanStats(String projectKey) {
   return actionPlanService.findActionPlanStats(projectKey, UserSession.get());
 }
コード例 #11
0
 public ActionPlan findActionPlan(String actionPlanKey) {
   return actionPlanService.findByKey(actionPlanKey, UserSession.get());
 }
コード例 #12
0
 public Collection<ActionPlan> findOpenActionPlans(String projectKey) {
   return actionPlanService.findOpenByProjectKey(projectKey, UserSession.get());
 }