import org.sonar.db.property.PropertyDto;
import org.sonar.server.project.Project;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test
public void branch_settings() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branchDto = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branchDto = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
Branch branch = mock(Branch.class);
- when(branch.getName()).thenReturn(branchDto.getBranch());
+ when(branch.getName()).thenReturn(branchName);
analysisMetadataHolder
.setProject(Project.from(project))
.setBranch(branch);
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
@Test
public void generate_keys_when_using_existing_branch() {
ComponentDto projectDto = dbTester.components().insertPublicProject();
- ComponentDto branchDto = dbTester.components().insertProjectBranch(projectDto);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto componentDto = dbTester.components().insertProjectBranch(projectDto, b -> b.setKey(branchName));
Branch branch = mock(Branch.class);
- when(branch.getName()).thenReturn(branchDto.getBranch());
+ when(branch.getName()).thenReturn(branchName);
when(branch.isMain()).thenReturn(false);
- when(branch.generateKey(any(), any())).thenReturn(branchDto.getKey());
+ when(branch.generateKey(any(), any())).thenReturn(componentDto.getKey());
analysisMetadataHolder.setRootComponentRef(ROOT_REF)
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(projectDto))
.setBranch(branch);
BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
- reportReader.putComponent(component(ROOT_REF, PROJECT, branchDto.getKey()));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, componentDto.getKey()));
underTest.execute(new TestComputationStepContext());
- verifyComponentByRef(ROOT_REF, branchDto.getKey(), analysisMetadataHolder.getProject().getName(), branchDto.uuid());
+ verifyComponentByRef(ROOT_REF, componentDto.getKey(), analysisMetadataHolder.getProject().getName(), componentDto.uuid());
}
@Test
.setUuid(PROJECT_VIEW_1_UUID)
.setName(PROJECT_VIEW_1_NAME)
.setDescription("project view description is not persisted")
- .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getKey(), analysisDate, project.getBranch()));
+ .setProjectViewAttributes(new ProjectViewAttributes(project.uuid(), project.getKey(), analysisDate, null));
}
private void persistComponents(ComponentDto... componentDtos) {
import org.sonar.db.RowNotFoundException;
import org.sonar.db.ce.CeActivityDto;
import org.sonar.db.ce.CeTaskTypes;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.notification.NotificationService;
if (notificationService.hasProjectSubscribersForTypes(projectUuid, singleton(ReportAnalysisFailureNotification.class))) {
try (DbSession dbSession = dbClient.openSession(false)) {
ComponentDto projectDto = dbClient.componentDao().selectOrFailByUuid(dbSession, projectUuid);
+ BranchDto branchDto = dbClient.branchDao().selectByUuid(dbSession, projectDto.branchUuid())
+ .orElseThrow(() -> new IllegalStateException("Could not find a branch for component uuid " + projectDto.uuid()));
checkScopeAndQualifier(projectDto);
CeActivityDto ceActivityDto = dbClient.ceActivityDao().selectByUuid(dbSession, ceTask.getUuid())
.orElseThrow(() -> new RowNotFoundException(format("CeActivity with uuid '%s' not found", ceTask.getUuid())));
- ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, error);
+ ReportAnalysisFailureNotificationBuilder taskFailureNotification = buildNotification(ceActivityDto, projectDto, branchDto, error);
ReportAnalysisFailureNotification notification = taskFailureNotificationSerializer.toNotification(taskFailureNotification);
notificationService.deliverEmails(singleton(notification));
"Component %s must be a project (scope=%s, qualifier=%s)", projectDto.uuid(), scope, qualifier);
}
- private ReportAnalysisFailureNotificationBuilder buildNotification(CeActivityDto ceActivityDto, ComponentDto projectDto, @Nullable Throwable error) {
+ private ReportAnalysisFailureNotificationBuilder buildNotification(CeActivityDto ceActivityDto, ComponentDto projectDto, BranchDto branchDto,
+ @Nullable Throwable error) {
+ String projectBranch = branchDto.isMain() ? null : branchDto.getBranchKey();
Long executedAt = ceActivityDto.getExecutedAt();
return new ReportAnalysisFailureNotificationBuilder(
new ReportAnalysisFailureNotificationBuilder.Project(
projectDto.uuid(),
projectDto.getKey(),
projectDto.name(),
- projectDto.getBranch()),
+ projectBranch),
new ReportAnalysisFailureNotificationBuilder.Task(
ceActivityDto.getUuid(),
ceActivityDto.getSubmittedAt(),
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentTesting.newDirectory;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
assertThat(notificationProject.getName()).isEqualTo(project.name());
assertThat(notificationProject.getKey()).isEqualTo(project.getKey());
assertThat(notificationProject.getUuid()).isEqualTo(project.uuid());
- assertThat(notificationProject.getBranchName()).isEqualTo(project.getBranch());
+ assertThat(notificationProject.getBranchName()).isEqualTo(DEFAULT_MAIN_BRANCH_NAME);
ReportAnalysisFailureNotificationBuilder.Task notificationTask = reportAnalysisFailureNotificationBuilder.getTask();
assertThat(notificationTask.getUuid()).isEqualTo(taskUuid);
assertThat(notificationTask.getCreatedAt()).isEqualTo(createdAt);
public static final String PULL_REQUEST_SEPARATOR = ":PULL_REQUEST:";
private static final Splitter BRANCH_KEY_SPLITTER = Splitter.on(BRANCH_KEY_SEPARATOR);
- private static final Splitter PULL_REQUEST_SPLITTER = Splitter.on(PULL_REQUEST_SEPARATOR);
public static final String UUID_PATH_SEPARATOR = ".";
public static final String UUID_PATH_OF_ROOT = UUID_PATH_SEPARATOR;
return this;
}
- /**
- * @return the key of the branch. It will be null on the main branch and when the component is not on a branch
- */
- @CheckForNull
- public String getBranch() {
- List<String> split = BRANCH_KEY_SPLITTER.splitToList(kee);
- return split.size() == 2 ? split.get(1) : null;
- }
-
public String scope() {
return scope;
}
.setRootUuid("uuid_3");
assertThat(componentDto.getKey()).isEqualTo("org.struts:struts-core:src/org/struts/RequestContext.java");
- assertThat(componentDto.getBranch()).isNull();
assertThat(componentDto.name()).isEqualTo("RequestContext.java");
assertThat(componentDto.longName()).isEqualTo("org.struts.RequestContext");
assertThat(componentDto.qualifier()).isEqualTo("FIL");
import com.google.common.base.Strings;
import java.util.List;
import java.util.Map;
-import java.util.function.Predicate;
-import org.apache.commons.lang.RandomStringUtils;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.audit.AuditPersister;
import org.sonar.db.audit.model.ComponentKeyNewValue;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
@Test
public void updateKey_updates_branches_too() {
ComponentDto project = db.components().insertPublicProject();
- String branchKey = RandomStringUtils.randomAlphanumeric(100);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchKey));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
db.components().insertComponent(newFileDto(branch));
db.components().insertComponent(newFileDto(branch));
int prComponentCount = 3;
assertThat(dbClient.componentDao().selectByKey(dbSession, oldProjectKey)).isEmpty();
assertThat(dbClient.componentDao().selectByKey(dbSession, newProjectKey)).isPresent();
- assertThat(dbClient.componentDao().selectByKeyAndBranch(dbSession, newProjectKey, branchKey)).isPresent();
+ assertThat(dbClient.componentDao().selectByKeyAndBranch(dbSession, newProjectKey, branchName)).isPresent();
assertThat(dbClient.componentDao().selectByBranchUuid(project.uuid(), dbSession)).hasSize(1);
assertThat(dbClient.componentDao().selectByBranchUuid(branch.uuid(), dbSession)).hasSize(prComponentCount);
@Test
public void updateKey_updates_pull_requests_too() {
ComponentDto project = db.components().insertPublicProject();
- String pullRequestKey1 = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey1 = randomAlphanumeric(100);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1));
db.components().insertComponent(newFileDto(pullRequest));
db.components().insertComponent(newFileDto(pullRequest));
import static com.google.common.base.Preconditions.checkArgument;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType) {
boolean isMain = branchComponent.getMainBranchProjectUuid() == null;
String projectUuid = isMain ? branchComponent.uuid() : branchComponent.getMainBranchProjectUuid();
- String key = isMain ? "master" : "branch_" + randomAlphanumeric(248);
+ String key = isMain ? DEFAULT_MAIN_BRANCH_NAME : "branch_" + randomAlphanumeric(248);
return new BranchDto()
.setKey(key)
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
@Test
public void search_issue_from_branch() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
assertThat(underTest.create(new SearchRequest()
.setProjects(singletonList(branch.getKey()))
- .setBranch(branch.getBranch())))
+ .setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(project.uuid()), false);
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(branch.getKey()))
- .setBranch(branch.getBranch())))
+ .setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(project.uuid()), false);
}
@Test
public void search_file_issue_from_branch() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(file.getKey()))
- .setBranch(branch.getBranch())))
+ .setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.componentUuids()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(file.uuid()), false);
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(branch.getKey()))
.setFiles(singletonList(file.path()))
- .setBranch(branch.getBranch())))
+ .setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.files()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(file.path()), false);
assertThat(underTest.create(new SearchRequest()
.setProjects(singletonList(branch.getKey()))
.setFiles(singletonList(file.path()))
- .setBranch(branch.getBranch())))
+ .setBranch(branchName)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.files()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(file.path()), false);
}
@Test
public void search_issue_on_component_only_from_branch() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(file.getKey()))
- .setBranch(branch.getBranch())
+ .setBranch(branchName)
.setOnComponentOnly(true)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.componentUuids()), IssueQuery::isMainBranch)
.containsOnly(branch.uuid(), singletonList(file.uuid()), false);
@Test
public void search_issues_from_main_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ db.components().insertProjectBranch(project);
assertThat(underTest.create(new SearchRequest()
.setProjects(singletonList(project.getKey()))
@Test
public void search_by_application_key_and_branch() {
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app"));
- ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
- ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
+ String branchName1 = "app-branch1";
+ String branchName2 = "app-branch2";
+ ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey(branchName1));
+ ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(branchName2));
ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
- ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
+ db.components().insertComponent(newFileDto(project1Branch1));
ComponentDto project1Branch2 = db.components().insertProjectBranch(project1);
ComponentDto project2 = db.components().insertPrivateProject(p -> p.setKey("prj2"));
db.components().insertComponents(newProjectCopy(project1Branch1, applicationBranch1));
// Search on applicationBranch1
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(applicationBranch1.getKey()))
- .setBranch(applicationBranch1.getBranch())))
+ .setBranch(branchName1)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
.containsOnly(applicationBranch1.uuid(), Collections.emptyList(), false);
assertThat(underTest.create(new SearchRequest()
.setComponents(singletonList(applicationBranch1.getKey()))
.setProjects(singletonList(project1.getKey()))
- .setBranch(applicationBranch1.getBranch())))
+ .setBranch(branchName1)))
.extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
.containsOnly(applicationBranch1.uuid(), singletonList(project1.uuid()), false);
}
});
if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) {
wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate()));
- if (Arrays.asList(Qualifiers.PROJECT, Qualifiers.APP).contains(dto.qualifier()) && dto.getBranch() != null && parentProjectDto != null) {
+ if (Arrays.asList(Qualifiers.PROJECT, Qualifiers.APP).contains(dto.qualifier()) && dto.getMainBranchProjectUuid() != null && parentProjectDto != null) {
wsComponent.getTagsBuilder().addAllTags(parentProjectDto.getTags());
}
}
import org.sonar.api.web.UserRole;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.permission.GlobalPermission;
import org.sonar.db.property.PropertyDto;
import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.user.UserSession;
import org.sonarqube.ws.Settings;
import org.sonarqube.ws.Settings.ValuesWsResponse;
try (DbSession dbSession = dbClient.openSession(true)) {
ValuesRequest valuesRequest = ValuesRequest.from(request);
Optional<ComponentDto> component = loadComponent(dbSession, valuesRequest);
+ BranchDto branchDto = loadBranch(dbSession, component);
Set<String> keys = loadKeys(valuesRequest);
Map<String, String> keysToDisplayMap = getKeysToDisplayMap(keys);
- List<Setting> settings = loadSettings(dbSession, component, keysToDisplayMap.keySet());
+ List<Setting> settings = loadSettings(dbSession, component, keysToDisplayMap.keySet(), branchDto);
return new ValuesResponseBuilder(settings, component, keysToDisplayMap).build();
}
}
+ private BranchDto loadBranch(DbSession dbSession, Optional<ComponentDto> component) {
+ if (component.isEmpty()) {
+ return null;
+ }
+ return dbClient.branchDao().selectByUuid(dbSession, component.get().branchUuid())
+ .orElseThrow(() -> new NotFoundException("Could not find a branch for component uuid " + component.get().branchUuid()));
+ }
+
private Set<String> loadKeys(ValuesRequest valuesRequest) {
List<String> keys = valuesRequest.getKeys();
Set<String> result;
return Optional.of(component);
}
- private List<Setting> loadSettings(DbSession dbSession, Optional<ComponentDto> component, Set<String> keys) {
+ private List<Setting> loadSettings(DbSession dbSession, Optional<ComponentDto> component, Set<String> keys, @Nullable BranchDto branchDto) {
// List of settings must be kept in the following orders : default -> global -> component -> branch
List<Setting> settings = new ArrayList<>();
settings.addAll(loadDefaultValues(keys));
settings.addAll(loadGlobalSettings(dbSession, keys));
- if (component.isPresent() && component.get().getBranch() != null && component.get().getMainBranchProjectUuid() != null) {
+ String branch = getBranchKeySafely(branchDto);
+ if (component.isPresent() && branch != null && component.get().getMainBranchProjectUuid() != null) {
ComponentDto project = dbClient.componentDao().selectOrFailByUuid(dbSession, component.get().getMainBranchProjectUuid());
settings.addAll(loadComponentSettings(dbSession, keys, project).values());
}
.collect(Collectors.toList());
}
+ private String getBranchKeySafely(@Nullable BranchDto branchDto) {
+ if(branchDto != null) {
+ return branchDto.isMain() ? null : branchDto.getBranchKey();
+ }
+ return null;
+ }
+
private List<Setting> loadDefaultValues(Set<String> keys) {
return propertyDefinitions.getAll().stream()
.filter(definition -> keys.contains(definition.key()))
import org.sonar.api.web.page.Page;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
+import org.sonar.db.component.BranchDto;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.measure.LiveMeasureDto;
import org.sonar.db.qualityprofile.QProfileDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.exceptions.BadRequestException;
+import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.project.Visibility;
import org.sonar.server.qualitygate.QualityGateFinder;
import org.sonar.server.qualityprofile.QPMeasureData;
import org.sonar.server.ui.PageRepository;
import org.sonar.server.user.UserSession;
+import static java.lang.String.format;
import static java.util.Collections.emptySortedSet;
import static org.sonar.api.CoreProperties.CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_DEFAULT_VALUE;
import static org.sonar.api.CoreProperties.CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY;
.setSince("5.2")
.setChangelog(
new Change("8.8", "Deprecated parameter 'componentKey' has been removed. Please use parameter 'component' instead"),
- new Change("7.6", String.format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
+ new Change("7.6", format("The use of module keys in parameter '%s' is deprecated", PARAM_COMPONENT)),
new Change("7.3", "The 'almRepoUrl' and 'almId' fields are added"),
new Change("6.4", "The 'visibility' field is added"));
throw insufficientPrivilegesException();
}
Optional<SnapshotDto> analysis = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, component.branchUuid());
+ BranchDto branchDto = dbClient.branchDao().selectByUuid(session, component.branchUuid())
+ .orElseThrow(() -> new NotFoundException(format("Could not find a branch for component uuid " + component.uuid())));
try (JsonWriter json = response.newJsonWriter()) {
json.beginObject();
boolean isFavourite = isFavourite(session, rootProject, component);
- writeComponent(json, component, analysis.orElse(null), isFavourite);
+ String branchKey = branchDto.isMain() ? null : branchDto.getBranchKey();
+ writeComponent(json, component, analysis.orElse(null), isFavourite, branchKey);
writeProfiles(json, session, component);
writeQualityGate(json, session, rootProject);
if (userSession.hasComponentPermission(ADMIN, component) ||
.endObject();
}
- private void writeComponent(JsonWriter json, ComponentDto component, @Nullable SnapshotDto analysis, boolean isFavourite) {
+ private void writeComponent(JsonWriter json, ComponentDto component, @Nullable SnapshotDto analysis, boolean isFavourite, String branchKey) {
json.prop("key", component.getKey())
.prop("id", component.uuid())
.prop("name", component.name())
.prop("description", component.description())
.prop("isFavorite", isFavourite);
- String branch = component.getBranch();
- if (branch != null) {
- json.prop("branch", branch);
+ if (branchKey != null) {
+ json.prop("branch", branchKey);
}
if (Qualifiers.APP.equals(component.qualifier())) {
json.prop("canBrowseAllChildProjects", userSession.hasChildProjectsPermission(USER, component));
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
ComponentDto project = db.components().insertPublicProject(p -> p.setPrivate(false));
userSession.registerComponents(project);
MetricDto metric = createIntMetricAndMeasure(project, BUGS_KEY, 5_000);
-
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
db.measures().insertLiveMeasure(branch, metric, m -> m.setValue(10_000d));
TestResponse response = ws.newRequest()
.setParam("project", branch.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.setParam("metric", metric.getKey())
.execute();
response = ws.newRequest()
.setHeader("If-None-Match", response.getHeader("ETag"))
.setParam("project", branch.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.setParam("metric", metric.getKey())
.execute();
import org.sonar.server.ws.TestResponse;
import org.sonar.server.ws.WsActionTester;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
userSession.registerComponents(project);
MetricDto metric = createQualityGateMetric();
db.measures().insertLiveMeasure(project, metric, m -> m.setData(OK.name()));
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
db.measures().insertLiveMeasure(branch, metric, m -> m.setData(ERROR.name()));
TestResponse response = ws.newRequest()
.setParam("project", branch.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute();
checkResponse(response, ERROR);
logInAsSystemAdministrator();
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = "branch1";
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
SnapshotDto analysis = db.components().insertSnapshot(branch);
CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
- insertCharacteristic(activity, BRANCH_KEY, branch.getBranch());
+ insertCharacteristic(activity, BRANCH_KEY, branchName);
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name());
ActivityResponse response = ws.newRequest().executeProtobuf(ActivityResponse.class);
assertThat(response.getTasksList())
.extracting(Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey)
.containsExactlyInAnyOrder(
- tuple("T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, branch.getKey()));
+ tuple("T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, branch.getKey()));
}
@Test
import org.sonarqube.ws.MediaTypes;
import static java.util.Collections.emptyList;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
public void branch_in_activity() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
SnapshotDto analysis = db.components().insertSnapshot(branch);
CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
- insertCharacteristic(activity, BRANCH_KEY, branch.getBranch());
+ insertCharacteristic(activity, BRANCH_KEY, branchName);
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name());
Ce.ComponentResponse response = ws.newRequest()
assertThat(response.getCurrent())
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
.containsOnly(
- "T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, project.getKey(), 0, emptyList());
+ "T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.SUCCESS, project.getKey(), 0, emptyList());
}
@Test
public void branch_in_queue_analysis() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
CeQueueDto queue1 = insertQueue("T1", project, IN_PROGRESS);
- insertCharacteristic(queue1, BRANCH_KEY, branch.getBranch());
+ insertCharacteristic(queue1, BRANCH_KEY, branchName);
insertCharacteristic(queue1, BRANCH_TYPE_KEY, BRANCH.name());
CeQueueDto queue2 = insertQueue("T2", project, PENDING);
- insertCharacteristic(queue2, BRANCH_KEY, branch.getBranch());
+ insertCharacteristic(queue2, BRANCH_KEY, branchName);
insertCharacteristic(queue2, BRANCH_TYPE_KEY, BRANCH.name());
Ce.ComponentResponse response = ws.newRequest()
assertThat(response.getQueueList())
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getStatus, Ce.Task::getComponentKey, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
.containsOnly(
- tuple("T1", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS, project.getKey(), 0, emptyList()),
- tuple("T2", branch.getBranch(), Common.BranchType.BRANCH, Ce.TaskStatus.PENDING, project.getKey(), 0, emptyList()));
+ tuple("T1", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.IN_PROGRESS, project.getKey(), 0, emptyList()),
+ tuple("T2", branchName, Common.BranchType.BRANCH, Ce.TaskStatus.PENDING, project.getKey(), 0, emptyList()));
}
@Test
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
insertQueue("Main", project, IN_PROGRESS);
+ String branchName1 = "Branch1";
ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch1"));
CeQueueDto branchQueue1 = insertQueue("Branch1", project, IN_PROGRESS);
- insertCharacteristic(branchQueue1, BRANCH_KEY, branch1.getBranch());
+ insertCharacteristic(branchQueue1, BRANCH_KEY, branchName1);
insertCharacteristic(branchQueue1, BRANCH_TYPE_KEY, BRANCH.name());
ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch2"));
+ String branchName2 = "Branch2";
CeQueueDto branchQueue2 = insertQueue("Branch2", project, PENDING);
- insertCharacteristic(branchQueue2, BRANCH_KEY, branch2.getBranch());
+ insertCharacteristic(branchQueue2, BRANCH_KEY, branchName2);
insertCharacteristic(branchQueue2, BRANCH_TYPE_KEY, BRANCH.name());
Ce.ComponentResponse response = ws.newRequest()
.extracting(Ce.Task::getId, Ce.Task::getComponentKey, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getWarningCount, Ce.Task::getWarningsList)
.containsOnly(
tuple("Main", project.getKey(), "", Common.BranchType.UNKNOWN_BRANCH_TYPE, 0, emptyList()),
- tuple("Branch1", branch1.getKey(), branch1.getBranch(), Common.BranchType.BRANCH, 0, emptyList()),
- tuple("Branch2", branch2.getKey(), branch2.getBranch(), Common.BranchType.BRANCH, 0, emptyList()));
+ tuple("Branch1", branch1.getKey(), branchName1, Common.BranchType.BRANCH, 0, emptyList()),
+ tuple("Branch2", branch2.getKey(), branchName2, Common.BranchType.BRANCH, 0, emptyList()));
}
@Test
import org.sonarqube.ws.Common;
import static java.util.Collections.singleton;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.web.UserRole.ADMIN;
logInAsSystemAdministrator();
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
db.components().insertSnapshot(branch);
CeActivityDto activity = createAndPersistArchivedTask(project);
- insertCharacteristic(activity, BRANCH_KEY, branch.getBranch());
+ insertCharacteristic(activity, BRANCH_KEY, branchName);
insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name());
Ce.TaskResponse taskResponse = ws.newRequest()
assertThat(taskResponse.getTask())
.extracting(Ce.Task::getId, Ce.Task::getBranch, Ce.Task::getBranchType, Ce.Task::getComponentKey)
- .containsExactlyInAnyOrder(SOME_TASK_UUID, branch.getBranch(), Common.BranchType.BRANCH, branch.getKey());
+ .containsExactlyInAnyOrder(SOME_TASK_UUID, branchName, Common.BranchType.BRANCH, branch.getKey());
}
@Test
import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.measures.CoreMetrics.COVERAGE_KEY;
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn("john").addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto module = db.components().insertComponent(newModuleDto(branch));
ComponentDto directory = db.components().insertComponent(newDirectory(module, "src"));
ComponentDto file = db.components().insertComponent(newFileDto(module, directory));
String result = ws.newRequest()
.setParam("component", file.getKey())
- .setParam("branch", file.getBranch())
+ .setParam("branch", branchName)
.execute()
.getInput();
assertJson(result).isSimilarTo("{\n" +
" \"key\": \"" + file.getKey() + "\",\n" +
- " \"branch\": \"" + file.getBranch() + "\",\n" +
+ " \"branch\": \"" + branchName + "\",\n" +
" \"uuid\": \"" + file.uuid() + "\",\n" +
" \"path\": \"" + file.path() + "\",\n" +
" \"name\": \"" + file.name() + "\",\n" +
public void component_and_branch_parameters_provided() {
ComponentDto project = db.components().insertPrivateProject();
userSession.logIn("john").addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
String result = ws.newRequest()
.setParam("component", file.getKey())
- .setParam("branch", file.getBranch())
+ .setParam("branch", branchName)
.execute()
.getInput();
assertJson(result).isSimilarTo("{\n" +
" \"key\": \"" + file.getKey() + "\",\n" +
- " \"branch\": \"" + file.getBranch() + "\",\n" +
+ " \"branch\": \"" + branchName + "\",\n" +
" \"uuid\": \"" + file.uuid() + "\",\n" +
" \"path\": \"" + file.path() + "\",\n" +
" \"name\": \"" + file.name() + "\",\n" +
import java.util.Date;
import java.util.Optional;
import javax.annotation.Nullable;
-import org.apache.commons.lang.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
import org.sonarqube.ws.Components.Component;
import org.sonarqube.ws.Components.ShowWsResponse;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
ComponentDto portfolio2 = db.components().insertPublicPortfolio();
ComponentDto subview = db.components().insertSubView(portfolio1);
- String pullRequestKey1 = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey1 = randomAlphanumeric(100);
ComponentDto project1 = db.components().insertPrivateProject();
ComponentDto branch1 = db.components().insertProjectBranch(project1, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey1)
.setNeedIssueSync(true));
ComponentDto file = db.components().insertComponent(newFileDto(directory));
ComponentDto project2 = db.components().insertPrivateProject();
- ComponentDto branch2 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(true));
- ComponentDto branch3 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(false));
+ String branchName2 = randomAlphanumeric(248);
+ ComponentDto branch2 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(true).setKey(branchName2));
+ String branchName3 = randomAlphanumeric(248);
+ ComponentDto branch3 = db.components().insertProjectBranch(project2, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName3));
ComponentDto project3 = db.components().insertPrivateProject();
- String pullRequestKey4 = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey4 = randomAlphanumeric(100);
ComponentDto branch4 = db.components().insertProjectBranch(project3, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey4).setNeedIssueSync(false));
ComponentDto moduleOfBranch4 = db.components().insertComponent(newModuleDto(branch4));
ComponentDto directoryOfBranch4 = db.components().insertComponent(newDirectory(moduleOfBranch4, "dir"));
ComponentDto fileOfBranch4 = db.components().insertComponent(newFileDto(directoryOfBranch4));
- ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false));
+ String branchName5 = randomAlphanumeric(248);
+ ComponentDto branch5 = db.components().insertProjectBranch(project3, b -> b.setBranchType(BRANCH).setNeedIssueSync(false).setKey(branchName5));
userSession.addProjectPermission(UserRole.USER, project1, project2, project3);
userSession.registerComponents(portfolio1, portfolio2, subview, project1, project2, project3);
assertNeedIssueSyncEqual(pullRequestKey1, null, file, true);
assertNeedIssueSyncEqual(null, null, project2, true);
- assertNeedIssueSyncEqual(null, branch2.getBranch(), branch2, true);
- assertNeedIssueSyncEqual(null, branch3.getBranch(), branch3, true);
+ assertNeedIssueSyncEqual(null, branchName2, branch2, true);
+ assertNeedIssueSyncEqual(null, branchName3, branch3, true);
// if all branches are synced, need issue sync on project is is set to false
assertNeedIssueSyncEqual(null, null, project3, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, moduleOfBranch4, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, directoryOfBranch4, false);
assertNeedIssueSyncEqual(pullRequestKey4, null, fileOfBranch4, false);
- assertNeedIssueSyncEqual(null, branch5.getBranch(), branch5, false);
+ assertNeedIssueSyncEqual(null, branchName5, branch5, false);
}
private void assertNeedIssueSyncEqual(@Nullable String pullRequest, @Nullable String branch, ComponentDto component, boolean needIssueSync) {
@Test
public void project_branch_reference_from_application_branch() {
ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app-key"));
- ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey("app-branch"));
+ String appBranchName = "app-branch";
+ String projectBranchName = "project-branch";
+ ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(appBranchName));
ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key"));
- ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
+ ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey(projectBranchName));
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
- .setKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getKey()));
+ .setKey(applicationBranch.getKey() + appBranchName + projectBranch.getKey()));
logInWithBrowsePermission(application);
TreeWsResponse result = ws.newRequest()
.setParam(MeasuresWsParameters.PARAM_COMPONENT, applicationBranch.getKey())
- .setParam(MeasuresWsParameters.PARAM_BRANCH, applicationBranch.getBranch())
+ .setParam(MeasuresWsParameters.PARAM_BRANCH, appBranchName)
.executeProtobuf(TreeWsResponse.class);
assertThat(result.getBaseComponent())
.extracting(Component::getKey, Component::getBranch)
- .containsExactlyInAnyOrder(applicationBranch.getKey(), applicationBranch.getBranch());
+ .containsExactlyInAnyOrder(applicationBranch.getKey(), appBranchName);
assertThat(result.getComponentsList())
.extracting(Component::getKey, Component::getBranch, Component::getRefId, Component::getRefKey)
- .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranch.getBranch(), projectBranch.uuid(), project.getKey()));
+ .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranchName, projectBranch.uuid(), project.getKey()));
}
@Test
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("branch1"));
+ String branchName1 = "branch1";
+ ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName1));
SnapshotDto branch1Analysis = insertAnalysis(branch1, 1_500_000_000_000L);
insertIssue(branch1, branch1Analysis);
insertIssue(branch1, branch1Analysis);
- ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey("branch"));
+ String branchName2 = "branch2";
+ ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH).setKey(branchName2));
SnapshotDto branch2Analysis = insertAnalysis(branch2, 1_300_000_000_000L);
insertIssue(branch2, branch2Analysis);
issueIndexer.indexAllIssues();
assertThat(result.getEventsList())
.extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink, Event::getDate)
.containsOnly(
- tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), branch1.getBranch()),
+ tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), branchName1),
format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", branch1.getKey(), encode(formatDateTime(from + 1_000L)),
- userSession.getLogin(), branch1.getBranch()),
+ userSession.getLogin(), branchName1),
formatDateTime(branch1Analysis.getCreatedAt())),
- tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch2.getBranch()),
+ tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branchName2),
format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", branch2.getKey(), encode(formatDateTime(from + 1_000L)),
- userSession.getLogin(), branch2.getBranch()),
+ userSession.getLogin(), branchName2),
formatDateTime(branch2Analysis.getCreatedAt())));
}
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey("nonMain"));
+ String nonMainBranchName = "nonMain";
+ ComponentDto nonMainBranch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(nonMainBranchName));
SnapshotDto nonMainBranchAnalysis = insertAnalysis(nonMainBranch, 1_500_000_000_000L);
insertIssue(nonMainBranch, nonMainBranchAnalysis);
insertIssue(nonMainBranch, nonMainBranchAnalysis);
assertThat(result.getEventsList())
.extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink, Event::getDate)
.containsOnly(
- tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), nonMainBranch.getBranch()),
+ tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s' on branch '%s'", project.name(), nonMainBranchName),
format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&branch=%s", nonMainBranch.getKey(), encode(formatDateTime(from + 1_000L)),
- userSession.getLogin(), nonMainBranch.getBranch()),
+ userSession.getLogin(), nonMainBranchName),
formatDateTime(nonMainBranchAnalysis.getCreatedAt())),
tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on pull request '%s'", project.name(), pullRequestKey),
format("https://sonarcloud.io/project/issues?id=%s&createdAfter=%s&assignees=%s&resolved=false&pullRequest=%s", pullRequest.getKey(),
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
- SnapshotDto projectAnalysis = insertSuccessfulActivity(project, 1_500_000_000_000L);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
+ insertSuccessfulActivity(project, 1_500_000_000_000L);
SnapshotDto branchAnalysis = insertSuccessfulActivity(branch, 1_500_000_000_000L);
insertActivity(branch, branchAnalysis, CeActivityDto.Status.SUCCESS);
db.events().insertEvent(newQualityGateEvent(branchAnalysis).setDate(branchAnalysis.getCreatedAt()).setName("Failed"));
.extracting(Event::getCategory, Event::getProject, Event::getMessage, Event::getLink)
.containsOnly(
tuple("QUALITY_GATE", project.getKey(),
- format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch()),
- format("https://sonarcloud.io/dashboard?id=%s&branch=%s", project.getKey(), branch.getBranch()))
+ format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branchName),
+ format("https://sonarcloud.io/dashboard?id=%s&branch=%s", project.getKey(), branchName))
);
}
when(server.getPublicRootUrl()).thenReturn("https://sonarcloud.io");
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
SnapshotDto projectAnalysis = insertAnalysis(project, 1_500_000_000_000L);
db.events().insertEvent(newQualityGateEvent(projectAnalysis).setDate(projectAnalysis.getCreatedAt()).setName("Passed"));
insertIssue(project, projectAnalysis);
.extracting(Event::getCategory, Event::getProject, Event::getMessage)
.containsOnly(
tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' changed to 'Passed'", project.name())),
- tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branch.getBranch())),
+ tuple("QUALITY_GATE", project.getKey(), format("Quality Gate status of project '%s' on branch '%s' changed to 'Failed'", project.name(), branchName)),
tuple("NEW_ISSUES", project.getKey(), format("You have 2 new issues on project '%s'", project.name())),
- tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branch.getBranch())));
+ tuple("NEW_ISSUES", project.getKey(), format("You have 1 new issue on project '%s' on branch '%s'", project.name(), branchName)));
verify(issueIndexSyncProgressChecker).checkIfAnyComponentsNeedIssueSync(any(), argThat(arg -> arg.contains(project.getKey())));
}
import org.sonar.db.component.ComponentDto;
import static java.lang.String.format;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.db.component.ComponentTesting.newFileDto;
@Test
public void duplication_on_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
- List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, branch.getBranch(), null,
+ List<DuplicationsParser.Block> blocks = parser.parse(db.getSession(), file1, branchName, null,
format("<duplications>\n" +
" <g>\n" +
" <b s=\"20\" l=\"5\" r=\"%s\"/>\n" +
package org.sonar.server.duplication.ws;
import java.util.function.Function;
-import org.apache.commons.lang.RandomStringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
public void duplications_by_file_key_and_branch() {
ComponentDto project = db.components().insertPrivateProject();
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
" <g>\n" +
String result = ws.newRequest()
.setParam("key", file.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute()
.getInput();
" }\n" +
" }\n" +
"}",
- file.getKey(), file.longName(), file.uuid(), branch.getKey(), branch.uuid(), project.longName(), file.getBranch()));
+ file.getKey(), file.longName(), file.uuid(), branch.getKey(), branch.uuid(), project.longName(), branchName));
}
@Test
public void duplications_by_file_key_and_pull_request() {
ComponentDto project = db.components().insertPrivateProject();
userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
- String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
ComponentDto file = db.components().insertComponent(newFileDto(pullRequest));
db.measures().insertLiveMeasure(file, dataMetric, m -> m.setData(format("<duplications>\n" +
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
-import org.apache.commons.lang.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.test.JsonAssert;
import static com.google.common.collect.Lists.newArrayList;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.sonar.db.component.BranchType.PULL_REQUEST;
import static org.sonar.db.component.ComponentTesting.newFileDto;
import static org.sonar.db.component.ComponentTesting.newModuleDto;
@Test
public void write_duplications_on_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file1 = db.components().insertComponent(newFileDto(branch));
ComponentDto file2 = db.components().insertComponent(newFileDto(branch));
List<DuplicationsParser.Block> blocks = newArrayList();
Duplication.newComponent(file1, 57, 12),
Duplication.newComponent(file2, 73, 12))));
- test(blocks, branch.getBranch(), null,
+ test(blocks, branchName, null,
"{\n" +
" \"duplications\": [\n" +
" {\n" +
" \"name\": \"" + file1.longName() + "\",\n" +
" \"project\": \"" + branch.getKey() + "\",\n" +
" \"projectName\": \"" + branch.longName() + "\",\n" +
- " \"branch\": \"" + branch.getBranch() + "\",\n" +
+ " \"branch\": \"" + branchName + "\",\n" +
" },\n" +
" \"2\": {\n" +
" \"key\": \"" + file2.getKey() + "\",\n" +
" \"name\": \"" + file2.longName() + "\",\n" +
" \"project\": \"" + branch.getKey() + "\",\n" +
" \"projectName\": \"" + branch.longName() + "\",\n" +
- " \"branch\": \"" + branch.getBranch() + "\",\n" +
+ " \"branch\": \"" + branchName + "\",\n" +
" }\n" +
" }" +
"}");
@Test
public void write_duplications_on_pull_request() {
ComponentDto project = db.components().insertPublicProject();
- String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
ComponentDto file1 = db.components().insertComponent(newFileDto(pullRequest));
ComponentDto file2 = db.components().insertComponent(newFileDto(pullRequest));
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.Nullable;
-import org.apache.commons.lang.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;
ComponentDto project = dbTester.components().insertPublicProject();
userSessionRule.registerComponents(project);
indexPermissions();
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
+ ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey("branch"));
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST).setKey("prKey"));
ComponentDto fileProject = dbTester.components().insertComponent(newFileDto(project));
ComponentDto fileBranch = dbTester.components().insertComponent(newFileDto(branch));
SearchWsResponse responseProject = newRequest(project)
.executeProtobuf(SearchWsResponse.class);
- SearchWsResponse responseBranch = newRequest(branch)
+ SearchWsResponse responseBranch = newRequest(branch, res -> res.setParam(PARAM_BRANCH, "branch"))
.executeProtobuf(SearchWsResponse.class);
SearchWsResponse responsePR = newRequest(pullRequest, res -> res.setParam(PARAM_PULL_REQUEST, "prKey"))
.executeProtobuf(SearchWsResponse.class);
@Test
public void returns_branch_field_of_components_of_branch() {
ComponentDto project = dbTester.components().insertPublicProject();
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
userSessionRule.registerComponents(project, branch);
indexPermissions();
ComponentDto directory = dbTester.components().insertComponent(newDirectory(branch, "donut/acme"));
IssueDto projectHotspot = insertHotspot(branch, branch, rule);
indexIssues();
- SearchWsResponse response = newRequest(branch)
+ SearchWsResponse response = newRequest(branch, r -> r.setParam(PARAM_BRANCH, branchName))
.executeProtobuf(SearchWsResponse.class);
assertThat(response.getHotspotsList())
.containsOnly(project.getKey(), directory.getKey(), file.getKey());
Map<String, Component> componentByKey = response.getComponentsList().stream().collect(uniqueIndex(Component::getKey));
Component actualProject = componentByKey.get(project.getKey());
- assertThat(actualProject.getBranch()).isEqualTo(branch.getBranch());
+ assertThat(actualProject.getBranch()).isEqualTo(branchName);
assertThat(actualProject.hasPullRequest()).isFalse();
Component actualDirectory = componentByKey.get(directory.getKey());
- assertThat(actualDirectory.getBranch()).isEqualTo(branch.getBranch());
+ assertThat(actualDirectory.getBranch()).isEqualTo(branchName);
assertThat(actualDirectory.hasPullRequest()).isFalse();
Component actualFile = componentByKey.get(file.getKey());
- assertThat(actualFile.getBranch()).isEqualTo(branch.getBranch());
+ assertThat(actualFile.getBranch()).isEqualTo(branchName);
assertThat(actualFile.hasPullRequest()).isFalse();
}
@Test
public void returns_pullRequest_field_of_components_of_pullRequest() {
ComponentDto project = dbTester.components().insertPublicProject();
- String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, t -> t.setBranchType(BranchType.PULL_REQUEST)
.setKey(pullRequestKey));
userSessionRule.registerComponents(project, pullRequest);
private TestRequest newRequest(ComponentDto project, @Nullable String status, @Nullable String resolution, Consumer<TestRequest> consumer) {
TestRequest res = actionTester.newRequest()
.setParam(PARAM_PROJECT_KEY, project.getKey());
- String branch = project.getBranch();
- if (branch != null) {
- res.setParam(PARAM_BRANCH, branch);
- }
if (status != null) {
res.setParam(PARAM_STATUS, status);
}
import java.util.stream.IntStream;
import java.util.stream.Stream;
import javax.annotation.Nullable;
-import org.apache.commons.lang.RandomStringUtils;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
import org.junit.Test;
import org.sonarqube.ws.Hotspots;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
@Test
public void returns_branch_but_no_pullRequest_on_component_and_project_on_non_main_branch() {
ComponentDto project = dbTester.components().insertPublicProject();
- ComponentDto branch = dbTester.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = dbTester.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = dbTester.components().insertComponent(newFileDto(branch));
userSessionRule.registerComponents(project);
RuleDto rule = newRule(SECURITY_HOTSPOT);
Hotspots.ShowWsResponse response = newRequest(hotspot)
.executeProtobuf(Hotspots.ShowWsResponse.class);
- verifyComponent(response.getProject(), branch, branch.getBranch(), null);
- verifyComponent(response.getComponent(), file, branch.getBranch(), null);
+ verifyComponent(response.getProject(), branch, branchName, null);
+ verifyComponent(response.getComponent(), file, branchName, null);
}
@Test
public void returns_pullRequest_but_no_branch_on_component_and_project_on_pullRequest() {
ComponentDto project = dbTester.components().insertPublicProject();
- String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = dbTester.components().insertProjectBranch(project,
t -> t.setBranchType(BranchType.PULL_REQUEST).setKey(pullRequestKey));
ComponentDto file = dbTester.components().insertComponent(newFileDto(pullRequest));
import java.time.Clock;
import java.util.Arrays;
import java.util.Date;
-import org.apache.commons.lang.RandomStringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.api.resources.Languages;
import org.sonarqube.ws.Issues.Issue;
import org.sonarqube.ws.Issues.SearchWsResponse;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.sonar.api.resources.Qualifiers.APP;
@Test
public void search_by_application_key_and_branch() {
ComponentDto application = db.components().insertPrivateProject(c -> c.setQualifier(APP).setKey("app"));
- ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch1"));
- ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey("app-branch2"));
+ String appBranch1 = "app-branch1";
+ String appBranch2 = "app-branch2";
+ ComponentDto applicationBranch1 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch1));
+ ComponentDto applicationBranch2 = db.components().insertProjectBranch(application, a -> a.setKey(appBranch2));
ComponentDto project1 = db.components().insertPrivateProject(p -> p.setKey("prj1"));
ComponentDto project1Branch1 = db.components().insertProjectBranch(project1);
ComponentDto fileOnProject1Branch1 = db.components().insertComponent(newFileDto(project1Branch1));
// All issues on applicationBranch1
assertThat(ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, applicationBranch1.getKey())
- .setParam(PARAM_BRANCH, applicationBranch1.getBranch())
+ .setParam(PARAM_BRANCH, appBranch1)
.executeProtobuf(SearchWsResponse.class).getIssuesList())
.extracting(Issue::getKey, Issue::getComponent, Issue::getProject, Issue::getBranch, Issue::hasBranch)
.containsExactlyInAnyOrder(
- tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true),
- tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch(), true),
+ tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getKey(), appBranch1, true),
+ tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getKey(), appBranch1, true),
tuple(issueOnProject2.getKey(), project2.getKey(), project2.getKey(), "", false));
// Issues on project1Branch1
assertThat(ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, applicationBranch1.getKey())
.setParam(PARAM_PROJECTS, project1.getKey())
- .setParam(PARAM_BRANCH, applicationBranch1.getBranch())
+ .setParam(PARAM_BRANCH, appBranch1)
.executeProtobuf(SearchWsResponse.class).getIssuesList())
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
.containsExactlyInAnyOrder(
- tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), project1Branch1.getBranch()),
- tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), project1Branch1.getBranch()));
+ tuple(issueOnProject1Branch1.getKey(), project1Branch1.getKey(), appBranch1),
+ tuple(issueOnFileOnProject1Branch1.getKey(), fileOnProject1Branch1.getKey(), appBranch1));
}
@Test
ComponentDto file = db.components().insertComponent(newFileDto(project));
IssueDto issue = db.issues().insertIssue(rule, project, file);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
allowAnyoneOnProjects(project);
// On component key + branch
assertThat(ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, project.getKey())
- .setParam(PARAM_BRANCH, branch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.executeProtobuf(SearchWsResponse.class).getIssuesList())
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
- .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
+ .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchName));
// On project key + branch
assertThat(ws.newRequest()
.setParam(PARAM_PROJECTS, project.getKey())
- .setParam(PARAM_BRANCH, branch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.executeProtobuf(SearchWsResponse.class).getIssuesList())
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
- .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
+ .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchName));
// On file key + branch
assertThat(ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, branchFile.getKey())
- .setParam(PARAM_BRANCH, branch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.executeProtobuf(SearchWsResponse.class).getIssuesList())
.extracting(Issue::getKey, Issue::getComponent, Issue::getBranch)
- .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchFile.getBranch()));
+ .containsExactlyInAnyOrder(tuple(branchIssue.getKey(), branchFile.getKey(), branchName));
}
@Test
ComponentDto project = db.components().insertPrivateProject();
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH));
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BRANCH).setKey(branchName));
ComponentDto branchFile = db.components().insertComponent(newFileDto(branch));
IssueDto branchIssue = db.issues().insertIssue(rule, branch, branchFile);
allowAnyoneOnProjects(project);
SearchWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT_KEYS, branch.getKey())
- .setParam(PARAM_BRANCH, branch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.executeProtobuf(SearchWsResponse.class);
assertThat(result.getComponentsList())
.extracting(Issues.Component::getKey, Issues.Component::getBranch)
.containsExactlyInAnyOrder(
- tuple(branchFile.getKey(), branchFile.getBranch()),
- tuple(branch.getKey(), branch.getBranch()));
+ tuple(branchFile.getKey(), branchName),
+ tuple(branch.getKey(), branchName));
}
@Test
ComponentDto projectFile = db.components().insertComponent(newFileDto(project));
IssueDto projectIssue = db.issues().insertIssue(rule, project, projectFile);
- String pullRequestKey = RandomStringUtils.randomAlphanumeric(100);
+ String pullRequestKey = randomAlphanumeric(100);
ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> b.setBranchType(PULL_REQUEST).setKey(pullRequestKey));
ComponentDto pullRequestFile = db.components().insertComponent(newFileDto(pullRequest));
IssueDto pullRequestIssue = db.issues().insertIssue(rule, pullRequest, pullRequestFile);
@Test
public void formatOperation_should_add_branch_on_issue() {
- componentDto.setKey(randomAlphanumeric(5) + BRANCH_KEY_SEPARATOR + randomAlphanumeric(5));
+ String branchName = randomAlphanumeric(5);
+ componentDto.setKey(randomAlphanumeric(5) + BRANCH_KEY_SEPARATOR + branchName);
Operation result = searchResponseFormat.formatOperation(searchResponseData);
- assertThat(result.getIssue().getBranch()).isEqualTo(componentDto.getBranch());
+ assertThat(result.getIssue().getBranch()).isEqualTo(branchName);
}
@Test
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- SnapshotDto analysis = db.components().insertSnapshot(branch);
+ String branchName = "my_branch";
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
+ db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m1 -> m1.setKey("complexity").setValueType("INT"));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d).setVariation(2.0d));
ComponentWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
- .setParam(PARAM_BRANCH, file.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.setParam(PARAM_METRIC_KEYS, complexity.getKey())
.executeProtobuf(ComponentWsResponse.class);
assertThat(response.getComponent()).extracting(Component::getKey, Component::getBranch)
- .containsExactlyInAnyOrder(file.getKey(), file.getBranch());
+ .containsExactlyInAnyOrder(file.getKey(), branchName);
assertThat(response.getComponent().getMeasuresList())
.extracting(Measures.Measure::getMetric, m -> parseDouble(m.getValue()))
.containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch"));
- SnapshotDto analysis = db.components().insertSnapshot(branch);
+ String branchName = "my-branch";
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
+ db.components().insertSnapshot(branch);
ComponentDto file = db.components().insertComponent(newFileDto(branch));
MetricDto complexity = db.measures().insertMetric(m -> m.setValueType(INT.name()));
LiveMeasureDto measure = db.measures().insertLiveMeasure(file, complexity, m -> m.setValue(12.0d));
ComponentTreeWsResponse response = ws.newRequest()
.setParam(PARAM_COMPONENT, file.getKey())
- .setParam(PARAM_BRANCH, file.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.setParam(PARAM_METRIC_KEYS, complexity.getKey())
.executeProtobuf(ComponentTreeWsResponse.class);
assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch)
- .containsExactlyInAnyOrder(file.getKey(), file.getBranch());
+ .containsExactlyInAnyOrder(file.getKey(), branchName);
assertThat(response.getBaseComponent().getMeasuresList())
.extracting(Measure::getMetric, m -> parseDouble(m.getValue()))
.containsExactlyInAnyOrder(tuple(complexity.getKey(), measure.getValue()));
MetricDto ncloc = insertNclocMetric();
ComponentDto application = db.components().insertPublicProject(c -> c.setQualifier(APP).setKey("app-key"));
userSession.registerApplication(application);
- ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey("app-branch"), a -> a.setUuid("custom-uuid"));
+ String branchName = "app-branch";
+ ComponentDto applicationBranch = db.components().insertProjectBranch(application, a -> a.setKey(branchName), a -> a.setUuid("custom-uuid"));
ComponentDto project = db.components().insertPrivateProject(p -> p.setKey("project-key"));
ComponentDto projectBranch = db.components().insertProjectBranch(project, b -> b.setKey("project-branch"));
ComponentDto techProjectBranch = db.components().insertComponent(newProjectCopy(projectBranch, applicationBranch)
- .setKey(applicationBranch.getKey() + applicationBranch.getBranch() + projectBranch.getKey()));
+ .setKey(applicationBranch.getKey() + branchName + projectBranch.getKey()));
SnapshotDto applicationBranchAnalysis = db.components().insertSnapshot(applicationBranch);
db.measures().insertLiveMeasure(applicationBranch, ncloc, m -> m.setValue(5d));
db.measures().insertLiveMeasure(techProjectBranch, ncloc, m -> m.setValue(1d));
ComponentTreeWsResponse result = ws.newRequest()
.setParam(PARAM_COMPONENT, applicationBranch.getKey())
- .setParam(PARAM_BRANCH, applicationBranch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.setParam(PARAM_METRIC_KEYS, ncloc.getKey())
.executeProtobuf(ComponentTreeWsResponse.class);
assertThat(result.getBaseComponent())
.extracting(Component::getKey, Component::getBranch)
- .containsExactlyInAnyOrder(applicationBranch.getKey(), applicationBranch.getBranch());
+ .containsExactlyInAnyOrder(applicationBranch.getKey(), branchName);
assertThat(result.getComponentsList())
.extracting(Component::getKey, Component::getBranch, Component::getRefKey)
- .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), projectBranch.getBranch(), project.getKey()));
+ .containsExactlyInAnyOrder(tuple(techProjectBranch.getKey(), branchName, project.getKey()));
}
@Test
import static java.util.Optional.ofNullable;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_BRANCH;
@Test
public void does_not_fail_and_has_no_effect_when_there_is_no_baseline_on_non_main_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
SnapshotDto analysis = db.components().insertSnapshot(project);
logInAsProjectAdministrator(project);
- call(project.getKey(), branch.getBranch());
+ call(project.getKey(), branchName);
verifyManualBaseline(branch, null);
}
@Test
public void unset_baseline_when_it_is_set_non_main_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
db.components().insertSnapshot(branch);
SnapshotDto branchAnalysis = db.components().insertSnapshot(project);
db.newCodePeriods().insert(project.branchUuid(), branch.uuid(), NewCodePeriodType.SPECIFIC_ANALYSIS, branchAnalysis.getUuid());
logInAsProjectAdministrator(project);
- call(project.getKey(), branch.getBranch());
+ call(project.getKey(), branchName);
verifyManualBaseline(branch, null);
}
@Test
public void fail_when_user_is_not_admin_on_project_of_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ db.components().insertProjectBranch(project, b -> b.setKey(branchName));
- assertThatThrownBy(() -> call(project.getKey(), branch.getBranch()))
+ assertThatThrownBy(() -> call(project.getKey(), branchName))
.isInstanceOf(ForbiddenException.class)
.hasMessage("Insufficient privileges");
}
import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Status;
import static java.lang.String.format;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.tuple;
@Test
public void return_live_status_when_branch_is_referenced_by_its_key() throws IOException {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
dbClient.snapshotDao().insert(dbSession, newAnalysis(branch)
.setPeriodMode("last_version")
String response = ws.newRequest()
.setParam(PARAM_PROJECT_KEY, project.getKey())
- .setParam(PARAM_BRANCH, branch.getBranch())
+ .setParam(PARAM_BRANCH, branchName)
.execute().getInput();
assertJson(response).isSimilarTo(getClass().getResource("project_status-example.json"));
import static java.lang.String.format;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.api.resources.Qualifiers.PROJECT;
@Test
public void remove_setting_on_branch() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
definitions.addComponent(PropertyDefinition.builder("foo").onQualifiers(PROJECT).build());
propertyDb.insertProperties(null, branch.name(), null, null, newComponentPropertyDto(branch).setKey("foo").setValue("value"));
userSession.logIn().addProjectPermission(ADMIN, project);
.setMediaType(MediaTypes.PROTOBUF)
.setParam("keys", "foo")
.setParam("component", branch.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute();
assertProjectPropertyDoesNotExist(branch, "foo");
public void branch() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.USER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
db.getDbClient().fileSourceDao().insert(db.getSession(), new FileSourceDto()
.setUuid(Uuids.createFast())
tester.newRequest()
.setParam("key", file.getKey())
- .setParam("branch", file.getBranch())
+ .setParam("branch", branchName)
.execute()
.assertJson(getClass(), "show_source.json");
}
import org.sonar.server.ws.WsActionTester;
import static java.lang.String.format;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.db.component.ComponentTesting.newFileDto;
public void raw_from_branch_file() {
ComponentDto project = db.components().insertPrivateProject();
userSession.addProjectPermission(UserRole.CODEVIEWER, project);
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
ComponentDto file = db.components().insertComponent(newFileDto(branch));
db.fileSources().insertFileSource(file, s -> s.setSourceData(
Data.newBuilder()
String result = ws.newRequest()
.setParam("key", file.getKey())
- .setParam("branch", file.getBranch())
+ .setParam("branch", branchName)
.execute().getInput();
assertThat(result).isEqualTo("public class HelloWorld {\n}\n");
@Test
public void return_favourite_for_branch() {
ComponentDto project = insertProject();
- ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1").setUuid("xyz"));
+ String branchName = "feature1";
+ componentDbTester.insertProjectBranch(project, b -> b.setKey(branchName).setUuid("xyz"));
UserDto user = db.users().insertUser("obiwan");
propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setComponentUuid(project.uuid()).setUserUuid(user.getUuid()),
project.getKey(), project.name(), project.qualifier(), user.getLogin());
String json = ws.newRequest()
.setParam("component", project.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute()
.getInput();
public void return_component_info_when_file_on_branch() {
db.qualityGates().createDefaultQualityGate();
ComponentDto project = componentDbTester.insertPrivateProject(p -> p.setName("Sample").setKey("sample"));
- ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey("feature1"));
+ String branchName = "feature1";
+ ComponentDto branch = componentDbTester.insertProjectBranch(project, b -> b.setKey(branchName));
userSession.addProjectPermission(UserRole.USER, project);
init();
ComponentDto dirDto = componentDbTester.insertComponent(newDirectory(branch, "src"));
String json = ws.newRequest()
.setParam("component", fileDto.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute()
.getInput();
import org.sonar.server.ws.WsActionTester;
import org.sonarqube.ws.Users.CurrentWsResponse;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@Test
public void return_homepage_when_set_to_a_branch() {
ComponentDto project = db.components().insertPrivateProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
UserDto user = db.users().insertUser(u -> u.setHomepageType("PROJECT").setHomepageParameter(branch.uuid()));
userSessionRule.logIn(user).addProjectPermission(USER, project);
assertThat(response.getHomepage())
.extracting(CurrentWsResponse.Homepage::getType, CurrentWsResponse.Homepage::getComponent, CurrentWsResponse.Homepage::getBranch)
- .containsExactly(CurrentWsResponse.HomepageType.PROJECT, branch.getKey(), branch.getBranch());
+ .containsExactly(CurrentWsResponse.HomepageType.PROJECT, branch.getKey(), branchName);
}
@Test
import org.sonar.server.ws.WsActionTester;
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.sonar.server.user.ws.SetHomepageAction.PARAM_COMPONENT;
@Test
public void set_branch_homepage() {
ComponentDto project = db.components().insertPublicProject();
- ComponentDto branch = db.components().insertProjectBranch(project);
+ String branchName = randomAlphanumeric(248);
+ ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(branchName));
UserDto user = db.users().insertUser();
userSession.logIn(user);
.setMethod("POST")
.setParam(PARAM_TYPE, "PROJECT")
.setParam("component", branch.getKey())
- .setParam("branch", branch.getBranch())
+ .setParam("branch", branchName)
.execute();
UserDto actual = db.getDbClient().userDao().selectByLogin(db.getSession(), user.getLogin());