@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(); }
public DefaultActionPlan toActionPlan() { return DefaultActionPlan.create(name) .setKey(kee) .setProjectKey(projectKey) .setDescription(description) .setStatus(status) .setDeadLine(deadLine) .setUserLogin(userLogin) .setCreatedAt(createdAt) .setUpdatedAt(updatedAt); }
@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")); }
@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; }
@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(); }