mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate);
}
- public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, @Nullable String qualifier, String componentKey, String componentName) {
+ public void setPrivateForRootComponentUuid(DbSession session, String branchUuid, boolean isPrivate, String qualifier, String componentKey, String componentName) {
ComponentNewValue componentNewValue = new ComponentNewValue(branchUuid, componentName, componentKey, isPrivate, qualifier);
auditPersister.updateComponentVisibility(session, componentNewValue);
mapper(session).setPrivateForRootComponentUuid(branchUuid, isPrivate);
@Test
public void select_by_keys_throws_ISE_if_both_branch_and_pr_are_passed() {
- assertThatThrownBy(() -> underTest.selectByKeys(db.getSession(), List.of("key"), "branch", "pr"))
+ DbSession session = db.getSession();
+ List<String> keys = List.of("key");
+ assertThatThrownBy(() -> underTest.selectByKeys(session, keys, "branch", "pr"))
.isInstanceOf(IllegalStateException.class);
}
.map(project2Component -> dbTester.issues().insert(rule, project2, project2Component).getKey())
.toArray(String[]::new);
- assertThat(issuesByKey(factory -> factory.createForBranch(project1.uuid())).keySet())
- .containsOnly(project1IssueKeys);
- assertThat(issuesByKey(factory -> factory.createForBranch(project2.uuid())).keySet())
- .containsOnly(project2IssueKeys);
+ assertThat(issuesByKey(factory -> factory.createForBranch(project1.uuid())))
+ .containsOnlyKeys(project1IssueKeys);
+ assertThat(issuesByKey(factory -> factory.createForBranch(project2.uuid())))
+ .containsOnlyKeys(project2IssueKeys);
assertThat(issuesByKey(factory -> factory.createForBranch("does not exist")))
.isEmpty();
}
return builder.build();
}
- Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component, BranchDto branchDto) {
- if (branchDto.isMain()) {
+ Hotspots.Component formatComponent(Hotspots.Component.Builder builder, ComponentDto component, @Nullable BranchDto branchDto) {
+ if (branchDto == null || branchDto.isMain()) {
return formatComponent(builder, component, null, null);
}
return formatComponent(builder, component, branchDto.getBranchKey(), branchDto.getPullRequestKey());
return componentCount;
}
- @CheckForNull
public Map<String, ComponentDto> getReferenceComponentsByUuid() {
return referenceComponentsByUuid;
}
try (DbSession dbSession = dbClient.openSession(true)) {
ValuesRequest valuesRequest = ValuesRequest.from(request);
Optional<ComponentDto> component = loadComponent(dbSession, valuesRequest);
- // TODO can portfolios fail here?
BranchDto branchDto = component.map(c -> componentFinder.getBranchByUuid(dbSession, c.branchUuid())).orElse(null);
Set<String> keys = loadKeys(valuesRequest);
}
@CheckForNull
- private String getBranchKeySafely(@Nullable BranchDto branchDto) {
+ private static String getBranchKeySafely(@Nullable BranchDto branchDto) {
if (branchDto != null) {
return branchDto.isMain() ? null : branchDto.getBranchKey();
}
import org.sonar.server.issue.index.IssueIteratorFactory;
import org.sonar.server.permission.index.PermissionIndexerTester;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Common.BranchType;
import org.sonarqube.ws.ProjectBranches;
ComponentDto project = db.components().insertPrivateProject();
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project));
userSession.logIn().addProjectPermission(USER, project);
-
- assertThatThrownBy(() -> ws.newRequest().setParam("project", file.getKey()).execute())
+ TestRequest request = ws.newRequest().setParam("project", file.getKey());
+ assertThatThrownBy(request::execute)
.isInstanceOf(NotFoundException.class)
.hasMessageContaining("Project '" + file.getKey() + "' not found");
}
userSession.logIn().setNonSystemAdministrator();
when(dispatchers.getGlobalDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
when(dispatchers.getProjectDispatchers()).thenReturn(singletonList(NOTIF_MY_NEW_ISSUES));
-
- assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, project.getKey(), userSession.getLogin()))
+ String key = project.getKey();
+ String login = userSession.getLogin();
+ assertThatThrownBy(() -> call(NOTIF_MY_NEW_ISSUES, null, key, login))
.isInstanceOf(ForbiddenException.class);
}
String branchName = randomAlphanumeric(248);
db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- assertThatThrownBy(() -> call(project.getKey(), branchName))
+ String key = project.getKey();
+ assertThatThrownBy(() -> call(key, branchName))
.isInstanceOf(ForbiddenException.class)
.hasMessage("Insufficient privileges");
}
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
public void fails_if_not_project_administrator() {
userSession.logIn();
- assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute())
+ TestRequest request = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey());
+ assertThatThrownBy(request::execute)
.isInstanceOf(ForbiddenException.class);
}
public void fails_to_trigger_task_if_anonymous() {
userSession.anonymous();
- assertThatThrownBy(() -> actionTester.newRequest().setMethod("POST").setParam("key", project.getKey()).execute())
+ TestRequest request = actionTester.newRequest().setMethod("POST").setParam("key", project.getKey());
+ assertThatThrownBy(request::execute)
.isInstanceOf(ForbiddenException.class)
.hasMessage("Insufficient privileges");
}
ComponentDto directory = componentDbTester.insertComponent(newDirectory(module, "src/main/xoo"));
userSession.addProjectPermission(UserRole.USER, project);
init();
-
- assertThatThrownBy(() -> execute(directory.getKey()))
+ String dirKey = directory.getKey();
+ assertThatThrownBy(() -> execute(dirKey))
.isInstanceOf(BadRequestException.class);
}