import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.issue.IssueDto;
import org.sonar.server.issue.IssueFieldsSetter;
import org.sonar.server.issue.IssueFinder;
import org.sonar.server.issue.IssueUpdater;
String issueKey = request.mandatoryParam(PARAM_ISSUE);
RuleType ruleType = RuleType.valueOf(request.mandatoryParam(PARAM_TYPE));
try (DbSession session = dbClient.openSession(false)) {
- setType(session, issueKey, ruleType);
+ SearchResponseData preloadedSearchResponseData = setType(session, issueKey, ruleType);
+ responseWriter.write(issueKey, preloadedSearchResponseData, request, response);
}
- responseWriter.write(issueKey, request, response);
}
- private void setType(DbSession session, String issueKey, RuleType ruleType) {
- DefaultIssue issue = issueFinder.getByKey(session, issueKey).toDefaultIssue();
+ private SearchResponseData setType(DbSession session, String issueKey, RuleType ruleType) {
+ IssueDto issueDto = issueFinder.getByKey(session, issueKey);
+ DefaultIssue issue = issueDto.toDefaultIssue();
userSession.checkComponentUuidPermission(ISSUE_ADMIN, issue.projectUuid());
IssueChangeContext context = IssueChangeContext.createUser(new Date(), userSession.getLogin());
if (issueFieldsSetter.setType(issue, ruleType, context)) {
- issueUpdater.saveIssue(session, issue, context, null);
+ return issueUpdater.saveIssueAndPreloadSearchResponseData(session, issue, context, null);
}
+ return new SearchResponseData(issueDto);
}
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
import org.sonar.api.config.MapSettings;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.issue.IssueDbTester;
import org.sonar.db.issue.IssueDto;
+import org.sonar.db.rule.RuleDefinitionDto;
import org.sonar.db.rule.RuleDto;
import org.sonar.server.es.EsTester;
import org.sonar.server.exceptions.ForbiddenException;
private IssueDbTester issueDbTester = new IssueDbTester(dbTester);
private DefaultOrganizationProvider defaultOrganizationProvider = TestDefaultOrganizationProvider.from(dbTester);
private OperationResponseWriter responseWriter = mock(OperationResponseWriter.class);
+ private ArgumentCaptor<SearchResponseData> preloadedSearchResponseDataCaptor = ArgumentCaptor.forClass(SearchResponseData.class);
private IssueIndexer issueIndexer = new IssueIndexer(esTester.client(), new IssueIteratorFactory(dbClient));
private WsActionTester tester = new WsActionTester(new SetTypeAction(userSession, dbClient, new IssueFinder(dbClient, userSession), new IssueFieldsSetter(),
call(issueDto.getKey(), BUG.name());
- verify(responseWriter).write(eq(issueDto.getKey()), any(Request.class), any(Response.class));
+ verify(responseWriter).write(eq(issueDto.getKey()), preloadedSearchResponseDataCaptor.capture(), any(Request.class), any(Response.class));
+ verifyContentOfPreloadedSearchResponseData(issueDto);
IssueDto issueReloaded = dbClient.issueDao().selectByKey(dbTester.getSession(), issueDto.getKey()).get();
assertThat(issueReloaded.getType()).isEqualTo(BUG.getDbConstant());
}
private void logInAndAddProjectPermission(String login, IssueDto issueDto, String permission) {
userSession.logIn(login).addProjectPermission(permission, dbClient.componentDao().selectByUuid(dbTester.getSession(), issueDto.getProjectUuid()).get());
}
+
+ private void verifyContentOfPreloadedSearchResponseData(IssueDto issue) {
+ SearchResponseData preloadedSearchResponseData = preloadedSearchResponseDataCaptor.getValue();
+ assertThat(preloadedSearchResponseData.getIssues())
+ .extracting(IssueDto::getKey)
+ .containsOnly(issue.getKey());
+ assertThat(preloadedSearchResponseData.getRules())
+ .extracting(RuleDefinitionDto::getKey)
+ .containsOnly(issue.getRuleKey());
+ assertThat(preloadedSearchResponseData.getComponents())
+ .extracting(ComponentDto::uuid)
+ .containsOnly(issue.getComponentUuid(), issue.getProjectUuid());
+ }
}