}
@Override
- protected int componentId(DefaultIssue issue) {
+ protected long componentId(DefaultIssue issue) {
Snapshot snapshot = getSnapshot(issue);
if (snapshot != null) {
return snapshot.getResourceId();
if (resourceDto == null) {
throw new IllegalStateException("Unknown component: " + issue.componentKey());
}
- return resourceDto.getId().intValue();
+ return resourceDto.getId();
}
@Override
- protected int projectId(DefaultIssue issue) {
+ protected long projectId(DefaultIssue issue) {
Snapshot snapshot = getSnapshot(issue);
if (snapshot != null) {
return snapshot.getRootProjectId();
when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123));
ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
- int componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(componentId).isEqualTo(123);
}
when(snapshotCache.get("struts:Action.java")).thenReturn(null);
ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
- int componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(componentId).isEqualTo(123);
}
when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123).setRootProjectId(100));
ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
- int projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(projectId).isEqualTo(100);
}
private Long id;
private String kee;
- private Integer componentId;
- private Integer rootComponentId;
+ private Long componentId;
+ private Long rootComponentId;
private Integer ruleId;
private String severity;
private boolean manualSeverity;
return this;
}
- public Integer getComponentId() {
+ public Long getComponentId() {
return componentId;
}
- public IssueDto setComponentId(Integer componentId) {
+ public IssueDto setComponentId(Long componentId) {
this.componentId = componentId;
return this;
}
- public Integer getRootComponentId() {
+ public Long getRootComponentId() {
return rootComponentId;
}
- public IssueDto setRootComponentId(Integer rootComponentId) {
+ public IssueDto setRootComponentId(Long rootComponentId) {
this.rootComponentId = rootComponentId;
return this;
}
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
- public static IssueDto toDtoForInsert(DefaultIssue issue, Integer componentId, Integer rootComponentId, Integer ruleId, Date now) {
+ public static IssueDto toDtoForInsert(DefaultIssue issue, Long componentId, Long rootComponentId, Integer ruleId, Date now) {
return new IssueDto()
.setKee(issue.key())
.setLine(issue.line())
List<DefaultIssue> conflicts = Lists.newArrayList();
for (DefaultIssue issue : issues) {
if (issue.isNew()) {
- int componentId = componentId(issue);
- int projectId = projectId(issue);
+ long componentId = componentId(issue);
+ long projectId = projectId(issue);
int ruleId = ruleId(issue);
IssueDto dto = IssueDto.toDtoForInsert(issue, componentId, projectId, ruleId, now);
issueMapper.insert(dto);
}
}
- protected abstract int componentId(DefaultIssue issue);
+ protected abstract long componentId(DefaultIssue issue);
- protected abstract int projectId(DefaultIssue issue);
+ protected abstract long projectId(DefaultIssue issue);
private int ruleId(Issue issue) {
Rule rule = ruleFinder.findByKey(issue.ruleKey());
return this;
}
- public Collection<Component> findByIds(Collection<Integer> ids) {
+ public Collection<Component> findByIds(Collection<Long> ids) {
if (ids.isEmpty()) {
return Collections.emptyList();
}
SqlSession session = mybatis.openSession();
try {
- List <List<Integer>> idsPartition = Lists.partition(newArrayList(ids), 1000);
+ List <List<Long>> idsPartition = Lists.partition(newArrayList(ids), 1000);
Collection<ResourceDto> resources = session.getMapper(ResourceMapper.class).selectResourcesById(idsPartition);
Collection<Component> components = newArrayList();
for (ResourceDto resourceDto : resources) {
/**
* @since3.6
*/
- List<ResourceDto> selectResourcesById(@Param("ids") List <List<Integer>> ids);
+ List<ResourceDto> selectResourcesById(@Param("ids") List <List<Long>> ids);
/**
* @since 3.6
this.mybatis = mybatis;
}
- public Set<Integer> keepAuthorizedComponentIds(Set<Integer> componentIds, @Nullable Integer userId, String role) {
+ public Set<Long> keepAuthorizedComponentIds(Set<Long> componentIds, @Nullable Integer userId, String role) {
SqlSession session = mybatis.openSession();
try {
return keepAuthorizedComponentIds(componentIds, userId, role, session);
}
}
- public Set<Integer> keepAuthorizedComponentIds(Set<Integer> componentIds, @Nullable Integer userId, String role, SqlSession session) {
+ public Set<Long> keepAuthorizedComponentIds(Set<Long> componentIds, @Nullable Integer userId, String role, SqlSession session) {
if (componentIds.isEmpty()) {
return Collections.emptySet();
}
String sql;
Map<String, Object> params;
- List<List<Integer>> componentIdsPartition = Lists.partition(newArrayList(componentIds), 1000);
+ List<List<Long>> componentIdsPartition = Lists.partition(newArrayList(componentIds), 1000);
if (userId == null) {
sql = "keepAuthorizedComponentIdsForAnonymous";
params = ImmutableMap.of("role", role, "componentIds", componentIdsPartition);
params = ImmutableMap.of("userId", userId, "role", role, "componentIds", componentIdsPartition);
}
- return Sets.newHashSet(session.<Integer>selectList(sql, params));
+ return Sets.newHashSet(session.<Long>selectList(sql, params));
}
- public boolean isAuthorizedComponentId(int componentId, @Nullable Integer userId, String role) {
+ public boolean isAuthorizedComponentId(long componentId, @Nullable Integer userId, String role) {
return keepAuthorizedComponentIds(Sets.newHashSet(componentId), userId, role).size() == 1;
}
- public Collection<Integer> selectAuthorizedRootProjectsIds(@Nullable Integer userId, String role) {
+ public Collection<Long> selectAuthorizedRootProjectsIds(@Nullable Integer userId, String role) {
SqlSession session = mybatis.openSession();
try {
return selectAuthorizedRootProjectsIds(userId, role, session);
}
}
- public Collection<Integer> selectAuthorizedRootProjectsIds(@Nullable Integer userId, String role, SqlSession session) {
+ public Collection<Long> selectAuthorizedRootProjectsIds(@Nullable Integer userId, String role, SqlSession session) {
String sql;
Map<String, Object> params = newHashMap();
sql = "selectAuthorizedRootProjectsIds";
<mapper namespace="org.sonar.core.user.AuthorizationMapper">
- <select id="keepAuthorizedComponentIdsForUser" parameterType="map" resultType="int">
+ <select id="keepAuthorizedComponentIdsForUser" parameterType="map" resultType="long">
SELECT s.project_id
FROM group_roles gr, snapshots s
WHERE
and s.islast = ${_true}
</select>
- <select id="keepAuthorizedComponentIdsForAnonymous" parameterType="map" resultType="int">
+ <select id="keepAuthorizedComponentIdsForAnonymous" parameterType="map" resultType="long">
SELECT s.project_id
FROM group_roles gr, snapshots s
WHERE
</foreach>
</select>
- <select id="selectAuthorizedRootProjectsIds" parameterType="map" resultType="int">
+ <select id="selectAuthorizedRootProjectsIds" parameterType="map" resultType="long">
<include refid="selectAuthorizedRootProjectsIdsQuery" />
</select>
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setComponentKey_unit_test_only("org.sonar.sample:Sample")
.setRootComponentKey_unit_test_only("org.sonar.sample")
- .setComponentId(1)
- .setRootComponentId(1)
+ .setComponentId(1l)
+ .setRootComponentId(1l)
.setStatus(Issue.STATUS_CLOSED)
.setResolution(Issue.RESOLUTION_FALSE_POSITIVE)
.setEffortToFix(15.0)
@Test
public void testInsert() throws Exception {
IssueDto dto = new IssueDto();
- dto.setComponentId(123);
- dto.setRootComponentId(100);
+ dto.setComponentId(123l);
+ dto.setRootComponentId(100l);
dto.setRuleId(200);
dto.setKee("ABCDE");
dto.setLine(500);
setupData("testUpdate");
IssueDto dto = new IssueDto();
- dto.setComponentId(123);
- dto.setRootComponentId(100);
+ dto.setComponentId(123l);
+ dto.setRootComponentId(100l);
dto.setRuleId(200);
dto.setKee("ABCDE");
dto.setLine(500);
}
@Override
- protected int componentId(DefaultIssue issue) {
- return 100;
+ protected long componentId(DefaultIssue issue) {
+ return 100l;
}
@Override
- protected int projectId(DefaultIssue issue) {
- return 10;
+ protected long projectId(DefaultIssue issue) {
+ return 10l;
}
}
public void should_find_components_by_resource_ids() {
setupData("fixture");
- Collection<Component> results = dao.findByIds(newArrayList(1));
+ Collection<Component> results = dao.findByIds(newArrayList(1l));
assertThat(results).hasSize(1);
Component component = results.iterator().next();
assertThat(component.key()).isNotNull();
public class AuthorizationDaoTest extends AbstractDaoTestCase {
private static final int USER = 100;
- private static final int PROJECT = 300, PACKAGE = 301, FILE = 302, FILE_IN_OTHER_PROJECT = 999;
+ private static final long PROJECT = 300l, PACKAGE = 301l, FILE = 302l, FILE_IN_OTHER_PROJECT = 999l;
@Test
public void user_should_be_authorized() {
setupData("user_should_be_authorized");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Set<Integer> componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Set<Long> componentIds = authorization.keepAuthorizedComponentIds(
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
USER, "user");
assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE);
// user does not have the role "admin"
componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE),
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE),
USER, "admin");
assertThat(componentIds).isEmpty();
}
setupData("group_should_be_authorized");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Set<Integer> componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Set<Long> componentIds = authorization.keepAuthorizedComponentIds(
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
USER, "user");
assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE);
// group does not have the role "admin"
componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
USER, "admin");
assertThat(componentIds).isEmpty();
}
setupData("group_should_have_global_authorization");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Set<Integer> componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Set<Long> componentIds = authorization.keepAuthorizedComponentIds(
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
USER, "user");
assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE);
// group does not have the role "admin"
componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
USER, "admin");
assertThat(componentIds).isEmpty();
}
setupData("anonymous_should_be_authorized");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Set<Integer> componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Set<Long> componentIds = authorization.keepAuthorizedComponentIds(
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
null, "user");
assertThat(componentIds).containsOnly(PROJECT, PACKAGE, FILE);
// group does not have the role "admin"
componentIds = authorization.keepAuthorizedComponentIds(
- Sets.<Integer>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
+ Sets.<Long>newHashSet(PROJECT, PACKAGE, FILE, FILE_IN_OTHER_PROJECT),
null, "admin");
assertThat(componentIds).isEmpty();
}
setupData("should_return_root_project_ids_for_user");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Collection<Integer> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(USER, "user");
+ Collection<Long> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(USER, "user");
assertThat(rootProjectIds).containsOnly(PROJECT);
setupData("should_return_root_project_ids_for_group");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Collection<Integer> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(USER, "user");
+ Collection<Long> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(USER, "user");
assertThat(rootProjectIds).containsOnly(PROJECT);
setupData("should_return_root_project_ids_for_anonymous");
AuthorizationDao authorization = new AuthorizationDao(getMyBatis());
- Collection<Integer> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(null, "user");
+ Collection<Long> rootProjectIds = authorization.selectAuthorizedRootProjectsIds(null, "user");
assertThat(rootProjectIds).containsOnly(PROJECT);
import com.google.common.collect.Iterables;
import org.sonar.api.ServerComponent;
import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.web.UserRole;
import org.sonar.core.issue.ActionPlanDeadlineComparator;
import org.sonar.core.issue.ActionPlanStats;
import org.sonar.core.issue.db.ActionPlanDao;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.resource.ResourceQuery;
+import org.sonar.core.user.AuthorizationDao;
+import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
private final ActionPlanDao actionPlanDao;
private final ActionPlanStatsDao actionPlanStatsDao;
private final ResourceDao resourceDao;
+ private final AuthorizationDao authorizationDao;
- public ActionPlanService(ActionPlanDao actionPlanDao, ActionPlanStatsDao actionPlanStatsDao, ResourceDao resourceDao) {
+ public ActionPlanService(ActionPlanDao actionPlanDao, ActionPlanStatsDao actionPlanStatsDao, ResourceDao resourceDao, AuthorizationDao authorizationDao) {
this.actionPlanDao = actionPlanDao;
this.actionPlanStatsDao = actionPlanStatsDao;
this.resourceDao = resourceDao;
+ this.authorizationDao = authorizationDao;
}
- public ActionPlan create(ActionPlan actionPlan){
- actionPlanDao.save(ActionPlanDto.toActionDto(actionPlan, findComponent(actionPlan.projectKey()).getId()));
+ public ActionPlan create(ActionPlan actionPlan, UserSession userSession) {
+ ResourceDto project = findProject(actionPlan.projectKey());
+ checkAuthorization(userSession, project, UserRole.ADMIN);
+ actionPlanDao.save(ActionPlanDto.toActionDto(actionPlan, project.getId()));
return actionPlan;
}
- public ActionPlan update(ActionPlan actionPlan){
- actionPlanDao.update(ActionPlanDto.toActionDto(actionPlan, findComponent(actionPlan.projectKey()).getId()));
+ public ActionPlan update(ActionPlan actionPlan, UserSession userSession) {
+ ResourceDto project = findProject(actionPlan.projectKey());
+ checkAuthorization(userSession, project, UserRole.ADMIN);
+ actionPlanDao.update(ActionPlanDto.toActionDto(actionPlan, project.getId()));
return actionPlan;
}
- public void delete(String key){
- actionPlanDao.delete(key);
+ public void delete(String actionPlanKey, UserSession userSession) {
+ checkAuthorization(userSession, findActionPlanDto(actionPlanKey).getProjectKey(), UserRole.ADMIN);
+ actionPlanDao.delete(actionPlanKey);
}
- public ActionPlan setStatus(String key, String status){
- ActionPlanDto actionPlanDto = actionPlanDao.findByKey(key);
- if (actionPlanDto == null) {
- throw new IllegalArgumentException("Action plan " + key + " has not been found.");
- }
+ public ActionPlan setStatus(String actionPlanKey, String status, UserSession userSession) {
+ ActionPlanDto actionPlanDto = findActionPlanDto(actionPlanKey);
+ checkAuthorization(userSession, actionPlanDto.getProjectKey(), UserRole.ADMIN);
+
actionPlanDto.setStatus(status);
actionPlanDto.setCreatedAt(new Date());
actionPlanDao.update(actionPlanDto);
}
@CheckForNull
- public ActionPlan findByKey(String key) {
+ public ActionPlan findByKey(String key, UserSession userSession) {
ActionPlanDto actionPlanDto = actionPlanDao.findByKey(key);
if (actionPlanDto == null) {
return null;
}
+ checkAuthorization(userSession, actionPlanDto.getProjectKey(), UserRole.USER);
return actionPlanDto.toActionPlan();
}
return toActionPlans(actionPlanDtos);
}
- public Collection<ActionPlan> findOpenByComponentKey(String componentKey) {
- List<ActionPlanDto> dtos = actionPlanDao.findOpenByProjectId(findRootProject(componentKey).getId());
+ public Collection<ActionPlan> findOpenByProjectKey(String projectKey, UserSession userSession) {
+ ResourceDto project = findProject(projectKey);
+ checkAuthorization(userSession, project, UserRole.USER);
+
+ List<ActionPlanDto> dtos = actionPlanDao.findOpenByProjectId(project.getId());
List<ActionPlan> plans = toActionPlans(dtos);
Collections.sort(plans, new ActionPlanDeadlineComparator());
return plans;
}
- public List<ActionPlanStats> findActionPlanStats(String projectKey) {
- List<ActionPlanStatsDto> actionPlanStatsDtos = actionPlanStatsDao.findByProjectId(findComponent(projectKey).getId());
+ public List<ActionPlanStats> findActionPlanStats(String projectKey, UserSession userSession) {
+ ResourceDto project = findProject(projectKey);
+ checkAuthorization(userSession, project, UserRole.USER);
+
+ List<ActionPlanStatsDto> actionPlanStatsDtos = actionPlanStatsDao.findByProjectId(project.getId());
List<ActionPlanStats> actionPlanStats = newArrayList(Iterables.transform(actionPlanStatsDtos, new Function<ActionPlanStatsDto, ActionPlanStats>() {
@Override
public ActionPlanStats apply(ActionPlanStatsDto actionPlanStatsDto) {
}
public boolean isNameAlreadyUsedForProject(String name, String projectKey) {
- return !actionPlanDao.findByNameAndProjectId(name, findComponent(projectKey).getId()).isEmpty();
+ return !actionPlanDao.findByNameAndProjectId(name, findProject(projectKey).getId()).isEmpty();
}
private List<ActionPlan> toActionPlans(List<ActionPlanDto> actionPlanDtos) {
}));
}
- private ResourceDto findComponent(String componentKey){
- ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(componentKey));
- if (resourceDto == null) {
- throw new IllegalArgumentException("Component " + componentKey + " does not exists.");
+ private ActionPlanDto findActionPlanDto(String actionPlanKey) {
+ ActionPlanDto actionPlanDto = actionPlanDao.findByKey(actionPlanKey);
+ if (actionPlanDto == null) {
+ throw new IllegalArgumentException("Action plan " + actionPlanKey + " has not been found.");
}
- return resourceDto;
+ return actionPlanDto;
}
- private ResourceDto findRootProject(String componentKey){
- ResourceDto resourceDto = resourceDao.getRootProjectByComponentKey(componentKey);
+ private ResourceDto findProject(String projectKey) {
+ ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(projectKey));
if (resourceDto == null) {
- throw new IllegalArgumentException("Component " + componentKey + " does not exists.");
+ throw new IllegalArgumentException("Project " + projectKey + " does not exists.");
}
return resourceDto;
}
+
+ private void checkAuthorization(UserSession userSession, String projectKey, String requiredRole) {
+ checkAuthorization(userSession, findProject(projectKey), requiredRole);
+ }
+
+ private void checkAuthorization(UserSession userSession, ResourceDto project, String requiredRole) {
+ if (!userSession.isLoggedIn()) {
+ // must be logged
+ throw new IllegalStateException("User is not logged in");
+ }
+ if (!authorizationDao.isAuthorizedComponentId(project.getId(), userSession.userId(), requiredRole)) {
+ throw new IllegalStateException("User does not have the required role to access the project: " + project.getKey());
+ }
+ }
+
}
throw new IllegalStateException("Unknown issue: " + issueKey);
}
if (!authorizationDao.isAuthorizedComponentId(dto.getComponentId(), UserSession.get().userId(), requiredRole)) {
- throw new IllegalStateException("User does not have the role " + requiredRole + " required to change the issue: " + issueKey);
+ throw new IllegalStateException("User does not have the required role required to change the issue: " + issueKey);
}
return dto.toDefaultIssue();
}
Map<String, DefaultIssue> issuesByKey = newHashMap();
List<Issue> issues = newArrayList();
Set<Integer> ruleIds = Sets.newHashSet();
- Set<Integer> componentIds = Sets.newHashSet();
- Set<Integer> projectIds = Sets.newHashSet();
+ Set<Long> componentIds = Sets.newHashSet();
+ Set<Long> projectIds = Sets.newHashSet();
Set<String> actionPlanKeys = Sets.newHashSet();
Set<String> users = Sets.newHashSet();
for (IssueDto dto : pagedSortedIssues) {
return userFinder.findByLogins(Lists.newArrayList(logins));
}
- private Collection<Component> findComponents(Set<Integer> componentIds) {
+ private Collection<Component> findComponents(Set<Long> componentIds) {
return resourceDao.findByIds(componentIds);
}
- private Collection<Component> findProjects(Set<Integer> projectIds) {
+ private Collection<Component> findProjects(Set<Long> projectIds) {
return resourceDao.findByIds(projectIds);
}
return result;
}
- public Collection<ActionPlan> findOpenActionPlansForComponent(String componentKey) {
- return actionPlanService.findOpenByComponentKey(componentKey);
+ public Collection<ActionPlan> findOpenActionPlans(String projectKey) {
+ return actionPlanService.findOpenByProjectKey(projectKey, UserSession.get());
}
public ActionPlan findActionPlan(String actionPlanKey) {
- return actionPlanService.findByKey(actionPlanKey);
+ return actionPlanService.findByKey(actionPlanKey, UserSession.get());
}
public List<ActionPlanStats> findActionPlanStats(String projectKey) {
- return actionPlanService.findActionPlanStats(projectKey);
+ return actionPlanService.findActionPlanStats(projectKey, UserSession.get());
}
public Result<ActionPlan> createActionPlan(Map<String, String> parameters) {
- // TODO verify authorization
-
Result<ActionPlan> result = createActionPlanResult(parameters);
if (result.ok()) {
- result.set(actionPlanService.create(result.get()));
+ result.set(actionPlanService.create(result.get(), UserSession.get()));
}
return result;
}
public Result<ActionPlan> updateActionPlan(String key, Map<String, String> parameters) {
- // TODO verify authorization
-
- DefaultActionPlan existingActionPlan = (DefaultActionPlan) actionPlanService.findByKey(key);
+ 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", key));
DefaultActionPlan actionPlan = (DefaultActionPlan) result.get();
actionPlan.setKey(existingActionPlan.key());
actionPlan.setUserLogin(existingActionPlan.userLogin());
- result.set(actionPlanService.update(actionPlan));
+ result.set(actionPlanService.update(actionPlan, UserSession.get()));
}
return result;
}
}
public Result<ActionPlan> closeActionPlan(String actionPlanKey) {
- // TODO verify authorization
Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
if (result.ok()) {
- result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_CLOSED));
+ result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_CLOSED, UserSession.get()));
}
return result;
}
public Result<ActionPlan> openActionPlan(String actionPlanKey) {
- // TODO verify authorization
Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
if (result.ok()) {
- result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN));
+ result.set(actionPlanService.setStatus(actionPlanKey, ActionPlan.STATUS_OPEN, UserSession.get()));
}
return result;
}
public Result<ActionPlan> deleteActionPlan(String actionPlanKey) {
- // TODO verify authorization
Result<ActionPlan> result = createResultForExistingActionPlan(actionPlanKey);
if (result.ok()) {
- actionPlanService.delete(actionPlanKey);
+ actionPlanService.delete(actionPlanKey, UserSession.get());
}
return result;
}
}
public Issue plan(String issueKey, @Nullable String actionPlanKey, UserSession userSession) {
- if (!Strings.isNullOrEmpty(actionPlanKey) && actionPlanService.findByKey(actionPlanKey) == null) {
+ if (!Strings.isNullOrEmpty(actionPlanKey) && actionPlanService.findByKey(actionPlanKey, userSession) == null) {
throw new IllegalStateException("Unknown action plan: " + actionPlanKey);
}
}
@Override
- protected int componentId(DefaultIssue issue) {
+ protected long componentId(DefaultIssue issue) {
ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(issue.componentKey()));
if (resourceDto == null) {
throw new IllegalStateException("Unknown component: " + issue.componentKey());
}
- return resourceDto.getId().intValue();
+ return resourceDto.getId();
}
@Override
- protected int projectId(DefaultIssue issue) {
+ protected long projectId(DefaultIssue issue) {
ResourceDto resourceDto = resourceDao.getRootProjectByComponentKey(issue.componentKey());
if (resourceDto == null) {
throw new IllegalStateException("Unknown component: " + issue.componentKey());
}
- return resourceDto.getId().intValue();
+ return resourceDto.getId();
}
}
<%
plans_select_box_id = "plans-#{params[:issue]}"
- plans = Internal.issues.findOpenActionPlansForComponent(@issue.componentKey())
+ plans = Internal.issues.findOpenActionPlans(@issue.componentKey())
if plans.empty?
%>
<% if is_admin? %>
<span class="error"><%= message('issue.plan.error.plan_must_be_created_first_for_admin',
- :params => ApplicationController.root_context + '/action_plans/index/' + @issue.projectKey()) -%></span>
+ :params => ApplicationController.root_context + '/action_plans/index/' + @issue_result.project(@issue).key()) -%></span>
<% else %>
<span class="error"><%= message('issue.plan.error.plan_must_be_created_first_for_other') -%></span>
<% end %>
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.web.UserRole;
import org.sonar.core.issue.ActionPlanStats;
import org.sonar.core.issue.DefaultActionPlan;
import org.sonar.core.issue.db.ActionPlanDao;
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.resource.ResourceQuery;
+import org.sonar.core.user.AuthorizationDao;
+import org.sonar.server.user.UserSession;
import java.util.Collection;
private ActionPlanDao actionPlanDao = mock(ActionPlanDao.class);
private ActionPlanStatsDao actionPlanStatsDao = mock(ActionPlanStatsDao.class);
private ResourceDao resourceDao = mock(ResourceDao.class);
+ private AuthorizationDao authorizationDao = mock(AuthorizationDao.class);
+ private UserSession userSession = mock(UserSession.class);
+
private ActionPlanService actionPlanService;
@Before
public void before() {
- actionPlanService = new ActionPlanService(actionPlanDao, actionPlanStatsDao, resourceDao);
+ when(userSession.isLoggedIn()).thenReturn(true);
+ when(userSession.userId()).thenReturn(10);
+ when(authorizationDao.isAuthorizedComponentId(anyLong(), eq(10), anyString())).thenReturn(true);
+
+ actionPlanService = new ActionPlanService(actionPlanDao, actionPlanStatsDao, resourceDao, authorizationDao);
}
@Test
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
ActionPlan actionPlan = DefaultActionPlan.create("Long term");
- actionPlanService.create(actionPlan);
+ actionPlanService.create(actionPlan, userSession);
verify(actionPlanDao).save(any(ActionPlanDto.class));
}
+ @Test
+ public void should_create_required_logged_user() {
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ ActionPlan actionPlan = DefaultActionPlan.create("Long term");
+ when(userSession.isLoggedIn()).thenReturn(false);
+
+ try {
+ actionPlanService.create(actionPlan, userSession);
+ } catch (Exception e){
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("User is not logged in");
+ }
+ verifyZeroInteractions(actionPlanDao);
+ }
+
+ @Test
+ public void should_create_required_admin_role() {
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ ActionPlan actionPlan = DefaultActionPlan.create("Long term");
+ when(authorizationDao.isAuthorizedComponentId(anyLong(), eq(10), anyString())).thenReturn(false);
+
+ try {
+ actionPlanService.create(actionPlan, userSession);
+ } catch (Exception e){
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("User does not have the required role to access the project: org.sonar.Sample");
+ }
+ verify(authorizationDao).isAuthorizedComponentId(eq(1l), eq(10), eq(UserRole.ADMIN));
+ verifyZeroInteractions(actionPlanDao);
+ }
+
@Test
public void should_set_status() {
when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD"));
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
- ActionPlan result = actionPlanService.setStatus("ABCD", "CLOSED");
+ ActionPlan result = actionPlanService.setStatus("ABCD", "CLOSED", userSession);
verify(actionPlanDao).update(any(ActionPlanDto.class));
assertThat(result).isNotNull();
assertThat(result.status()).isEqualTo("CLOSED");
}
+ @Test
+ public void should_update() {
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ ActionPlan actionPlan = DefaultActionPlan.create("Long term");
+
+ actionPlanService.update(actionPlan, userSession);
+ verify(actionPlanDao).update(any(ActionPlanDto.class));
+ }
+
@Test
public void should_delete() {
- actionPlanService.delete("ABCD");
+ when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD"));
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ actionPlanService.delete("ABCD", userSession);
verify(actionPlanDao).delete("ABCD");
}
@Test
public void should_find_by_key() {
when(actionPlanDao.findByKey("ABCD")).thenReturn(new ActionPlanDto().setKey("ABCD"));
- ActionPlan result = actionPlanService.findByKey("ABCD");
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+
+ ActionPlan result = actionPlanService.findByKey("ABCD", userSession);
assertThat(result).isNotNull();
assertThat(result.key()).isEqualTo("ABCD");
}
@Test
public void should_return_null_if_no_action_plan_when_find_by_key() {
when(actionPlanDao.findByKey("ABCD")).thenReturn(null);
- assertThat(actionPlanService.findByKey("ABCD")).isNull();
+ assertThat(actionPlanService.findByKey("ABCD", userSession)).isNull();
}
@Test
@Test
public void should_find_open_by_project_key() {
- when(resourceDao.getRootProjectByComponentKey("org.sonar.Sample")).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
when(actionPlanDao.findOpenByProjectId(1l)).thenReturn(newArrayList(new ActionPlanDto().setKey("ABCD")));
- Collection<ActionPlan> results = actionPlanService.findOpenByComponentKey("org.sonar.Sample");
+ Collection<ActionPlan> results = actionPlanService.findOpenByProjectKey("org.sonar.Sample", userSession);
assertThat(results).hasSize(1);
assertThat(results.iterator().next().key()).isEqualTo("ABCD");
}
+ @Test
+ public void should_find_open_by_project_key_required_user_role() {
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setKey("org.sonar.Sample").setId(1l));
+ when(actionPlanDao.findOpenByProjectId(1l)).thenReturn(newArrayList(new ActionPlanDto().setKey("ABCD")));
+ when(authorizationDao.isAuthorizedComponentId(anyLong(), eq(10), anyString())).thenReturn(false);
+
+ try {
+ actionPlanService.findOpenByProjectKey("org.sonar.Sample", userSession);
+ } catch (Exception e){
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("User does not have the required role to access the project: org.sonar.Sample");
+ }
+ verify(authorizationDao).isAuthorizedComponentId(eq(1l), eq(10), eq(UserRole.USER));
+ verifyZeroInteractions(actionPlanDao);
+ }
+
@Test(expected = IllegalArgumentException.class)
public void should_throw_exception_if_project_not_found_when_find_open_by_project_key() {
- when(resourceDao.getRootProjectByComponentKey(anyString())).thenReturn(null);
- actionPlanService.findOpenByComponentKey("<Unkown>");
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
+ actionPlanService.findOpenByProjectKey("<Unkown>", userSession);
}
@Test
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(1L).setKey("org.sonar.Sample"));
when(actionPlanStatsDao.findByProjectId(1L)).thenReturn(newArrayList(new ActionPlanStatsDto()));
- Collection<ActionPlanStats> results = actionPlanService.findActionPlanStats("org.sonar.Sample");
+ Collection<ActionPlanStats> results = actionPlanService.findActionPlanStats("org.sonar.Sample", userSession);
assertThat(results).hasSize(1);
}
public void should_throw_exception_if_project_not_found_when_find_open_action_plan_stats(){
when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
- actionPlanService.findActionPlanStats("org.sonar.Sample");
+ actionPlanService.findActionPlanStats("org.sonar.Sample", userSession);
}
}
public void should_find_issues() {
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
public void should_find_paginate_result() {
IssueQuery query = IssueQuery.builder().pageSize(1).pageIndex(1).build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(135).setRootComponentId(100)
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(135l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Phases.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
@Test
public void should_find_by_key() {
- IssueDto issueDto = new IssueDto().setId(1L).setRuleId(1).setComponentId(1).setRootComponentId(100)
+ IssueDto issueDto = new IssueDto().setId(1L).setRuleId(1).setComponentId(1l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100)
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l)
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100).setKee("ABC").setActionPlanKey("A")
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l).setKee("ABC").setActionPlanKey("A")
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100).setKee("DEF").setActionPlanKey("B")
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l).setKee("DEF").setActionPlanKey("B")
.setComponentKey_unit_test_only("Action.java")
.setRootComponentKey_unit_test_only("struts")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
IssueQuery query = IssueQuery.builder().build();
- IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123).setRootComponentId(100).setKee("ABC").setAssignee("perceval")
+ IssueDto issue1 = new IssueDto().setId(1L).setRuleId(50).setComponentId(123l).setRootComponentId(100l).setKee("ABC").setAssignee("perceval")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
- IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123).setRootComponentId(100).setKee("DEF").setReporter("arthur")
+ IssueDto issue2 = new IssueDto().setId(2L).setRuleId(50).setComponentId(123l).setRootComponentId(100l).setKee("DEF").setReporter("arthur")
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
List<IssueDto> dtoList = newArrayList(issue1, issue2);
import org.sonar.core.resource.ResourceDao;
import org.sonar.core.resource.ResourceDto;
import org.sonar.core.resource.ResourceQuery;
+import org.sonar.server.user.UserSession;
import java.util.Map;
Result result = internalRubyIssueService.createActionPlan(parameters);
assertThat(result.ok()).isTrue();
- verify(actionPlanService).create(actionPlanCaptor.capture());
+ verify(actionPlanService).create(actionPlanCaptor.capture(), any(UserSession.class));
ActionPlan actionPlan = actionPlanCaptor.getValue();
assertThat(actionPlan).isNotNull();
@Test
public void should_update_action_plan() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(DefaultActionPlan.create("Long term"));
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(DefaultActionPlan.create("Long term"));
Map<String, String> parameters = newHashMap();
parameters.put("name", "New Long term");
Result result = internalRubyIssueService.updateActionPlan("ABCD", parameters);
assertThat(result.ok()).isTrue();
- verify(actionPlanService).update(actionPlanCaptor.capture());
+ verify(actionPlanService).update(actionPlanCaptor.capture(), any(UserSession.class));
ActionPlan actionPlan = actionPlanCaptor.getValue();
assertThat(actionPlan).isNotNull();
@Test
public void should_update_action_plan_with_new_project() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(DefaultActionPlan.create("Long term"));
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(DefaultActionPlan.create("Long term"));
Map<String, String> parameters = newHashMap();
parameters.put("name", "New Long term");
Result result = internalRubyIssueService.updateActionPlan("ABCD", parameters);
assertThat(result.ok()).isTrue();
- verify(actionPlanService).update(actionPlanCaptor.capture());
+ verify(actionPlanService).update(actionPlanCaptor.capture(), any(UserSession.class));
ActionPlan actionPlan = actionPlanCaptor.getValue();
assertThat(actionPlan).isNotNull();
@Test
public void should_not_update_action_plan_when_action_plan_is_not_found() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(null);
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(null);
Result result = internalRubyIssueService.updateActionPlan("ABCD", null);
assertThat(result.ok()).isFalse();
@Test
public void should_delete_action_plan() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(DefaultActionPlan.create("Long term"));
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(DefaultActionPlan.create("Long term"));
Result result = internalRubyIssueService.deleteActionPlan("ABCD");
- verify(actionPlanService).delete("ABCD");
+ verify(actionPlanService).delete(eq("ABCD"), any(UserSession.class));
assertThat(result.ok()).isTrue();
}
@Test
public void should_not_delete_action_plan_if_action_plan_not_found() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(null);
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(null);
Result result = internalRubyIssueService.deleteActionPlan("ABCD");
- verify(actionPlanService, never()).delete("ABCD");
+ verify(actionPlanService, never()).delete(eq("ABCD"), any(UserSession.class));
assertThat(result.ok()).isFalse();
assertThat(result.errors()).contains(Result.Message.ofL10n("action_plans.errors.action_plan_does_not_exist", "ABCD"));
}
@Test
public void should_close_action_plan() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(DefaultActionPlan.create("Long term"));
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(DefaultActionPlan.create("Long term"));
Result result = internalRubyIssueService.closeActionPlan("ABCD");
- verify(actionPlanService).setStatus(eq("ABCD"), eq("CLOSED"));
+ verify(actionPlanService).setStatus(eq("ABCD"), eq("CLOSED"), any(UserSession.class));
assertThat(result.ok()).isTrue();
}
@Test
public void should_open_action_plan() {
- when(actionPlanService.findByKey("ABCD")).thenReturn(DefaultActionPlan.create("Long term"));
+ when(actionPlanService.findByKey(eq("ABCD"), any(UserSession.class))).thenReturn(DefaultActionPlan.create("Long term"));
Result result = internalRubyIssueService.openActionPlan("ABCD");
- verify(actionPlanService).setStatus(eq("ABCD"), eq("OPEN"));
+ verify(actionPlanService).setStatus(eq("ABCD"), eq("OPEN"), any(UserSession.class));
assertThat(result.ok()).isTrue();
}
setupData("should_load_component_id_from_db");
ServerIssueStorage storage = new ServerIssueStorage(getMyBatis(), new FakeRuleFinder(), new ResourceDao(getMyBatis()));
- int componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(componentId).isEqualTo(123);
}
setupData("should_load_project_id_from_db");
ServerIssueStorage storage = new ServerIssueStorage(getMyBatis(), new FakeRuleFinder(), new ResourceDao(getMyBatis()));
- int projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(projectId).isEqualTo(1);
}