@Override public boolean verify(Map<String, Object> properties, Collection<DefaultIssue> issues, UserSession userSession) { String assigneeLogin = getAssigneeValue(properties); UserDto assignee = isNullOrEmpty(assigneeLogin) ? null : getUser(assigneeLogin); properties.put(VERIFIED_ASSIGNEE, assignee); properties.put(ASSIGNEE_ORGANIZATIONS, loadUserOrganizations(assignee)); return true; }
@Override public boolean execute(Map<String, Object> properties, Context context) { checkArgument(properties.containsKey(VERIFIED_ASSIGNEE), "Assignee is missing from the execution parameters"); UserDto assignee = (UserDto) properties.get(VERIFIED_ASSIGNEE); return isAssigneeMemberOfIssueOrganization(assignee, properties, context) && issueFieldsSetter.assign(context.issue(), assignee, context.issueChangeContext()); }
@Test public void unassign_issue_if_assignee_is_null() { Map<String, Object> properties = new HashMap<>(); properties.put("assignee", null); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isNull(); }
@Test public void fail_if_assignee_does_not_exists() { expectedException.expect(NotFoundException.class); expectedException.expectMessage("Unknown user: arthur"); underTest.verify(ImmutableMap.of("assignee", "arthur"), singletonList(issue), userSession); }
@Test public void fail_if_assignee_is_not_verified() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Assignee is missing from the execution parameters"); underTest.execute(emptyMap(), context); }
private void addActions() { actions.add(new org.sonar.server.issue.AssignAction(db.getDbClient(), issueFieldsSetter)); actions.add(new org.sonar.server.issue.SetSeverityAction(issueFieldsSetter, userSession)); actions.add(new org.sonar.server.issue.SetTypeAction(issueFieldsSetter, userSession)); actions.add(new org.sonar.server.issue.TransitionAction(new TransitionService(userSession, issueWorkflow))); actions.add(new org.sonar.server.issue.AddTagsAction(issueFieldsSetter)); actions.add(new org.sonar.server.issue.RemoveTagsAction(issueFieldsSetter)); actions.add(new org.sonar.server.issue.CommentAction(issueFieldsSetter)); }
@Test public void fail_if_assignee_is_disabled() { db.users().insertUser(user -> user.setLogin("arthur").setActive(false)); expectedException.expect(NotFoundException.class); expectedException.expectMessage("Unknown user: arthur"); underTest.verify(new HashMap<>(ImmutableMap.of("assignee", "arthur")), singletonList(issue), userSession); }
@Override public boolean verify(Map<String, Object> properties, Collection<DefaultIssue> issues, UserSession userSession) { String assigneeLogin = getAssigneeValue(properties); UserDto assignee = isNullOrEmpty(assigneeLogin) ? null : getUser(assigneeLogin); properties.put(VERIFIED_ASSIGNEE, assignee); properties.put(ASSIGNEE_ORGANIZATIONS, loadUserOrganizations(assignee)); return true; }
@Test public void unassign_issue_if_assignee_is_empty() { Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isNull(); }
@Override public boolean execute(Map<String, Object> properties, Context context) { checkArgument(properties.containsKey(VERIFIED_ASSIGNEE), "Assignee is missing from the execution parameters"); UserDto assignee = (UserDto) properties.get(VERIFIED_ASSIGNEE); return isAssigneeMemberOfIssueOrganization(assignee, properties, context) && issueFieldsSetter.assign(context.issue(), assignee, context.issueChangeContext()); }
@Test public void does_not_assign_issue_when_assignee_is_not_member_of_project_issue_organization() { OrganizationDto otherOrganizationDto = db.organizations().insert(); UserDto assignee = db.users().insertUser("john"); // User is not member of the organization of the issue db.organizations().addMember(otherOrganizationDto, assignee); Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "john")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isFalse(); }
@Test public void assign_issue() { UserDto assignee = db.users().insertUser("john"); db.organizations().addMember(issueOrganizationDto, assignee); Map<String, Object> properties = new HashMap<>(ImmutableMap.of("assignee", "john")); underTest.verify(properties, Collections.emptyList(), userSession); boolean executeResult = underTest.execute(properties, context); assertThat(executeResult).isTrue(); assertThat(issue.assignee()).isEqualTo(assignee.getUuid()); }