use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method getGsonBBSRepo.
private Repository getGsonBBSRepo(Project project) {
Repository bbsResult = new Repository();
bbsResult.setProject(project);
bbsResult.setSlug(randomAlphanumeric(5));
bbsResult.setName(randomAlphanumeric(5));
bbsResult.setId(nextLong(100));
return bbsResult;
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method import_project_with_tilda.
@Test
public void import_project_with_tilda() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
project.setKey("~" + project.getKey());
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "~projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
String key = project.getKey() + "_" + repo.getSlug();
assertThat(result.getKey()).isNotEqualTo(key);
assertThat(result.getKey()).isEqualTo(key.substring(1));
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault.
@Test
public void handle_givenDefaultBranchNamedDefault_updateDefaultBranchNameToDefault() {
BranchesList branchesList = new BranchesList();
Branch branch = new Branch("default", true);
branchesList.addBranch(branch);
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(branchesList);
Projects.CreateWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").executeProtobuf(Projects.CreateWsResponse.class);
Projects.CreateWsResponse.Project result = response.getProject();
Optional<ProjectDto> projectDto = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), result.getKey());
Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
String mainBranchName = collect.iterator().next().getKey();
assertThat(mainBranchName).isEqualTo("default");
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class ImportBitbucketServerProjectActionTest method fail_project_already_exist.
@Test
public void fail_project_already_exist() {
UserDto user = db.users().insertUser();
userSession.logIn(user).addPermission(PROVISION_PROJECTS);
AlmSettingDto almSetting = db.almSettings().insertGitHubAlmSetting();
db.almPats().insert(dto -> {
dto.setAlmSettingUuid(almSetting.getUuid());
dto.setUserUuid(user.getUuid());
});
Project project = getGsonBBSProject();
Repository repo = getGsonBBSRepo(project);
String projectKey = project.getKey() + "_" + repo.getSlug();
db.components().insertPublicProject(p -> p.setDbKey(projectKey));
assertThatThrownBy(() -> {
when(bitbucketServerRestClient.getRepo(any(), any(), any(), any())).thenReturn(repo);
when(bitbucketServerRestClient.getBranches(any(), any(), any(), any())).thenReturn(defaultBranchesList);
ws.newRequest().setParam("almSetting", almSetting.getKey()).setParam("projectKey", "projectKey").setParam("repositorySlug", "repo-slug").execute();
}).isInstanceOf(BadRequestException.class).hasMessage("Could not create null, key already exists: " + projectKey);
}
use of org.sonar.alm.client.bitbucketserver.Repository in project sonarqube by SonarSource.
the class SearchBitbucketServerReposActionTest method getGsonBBSRepo1.
private Repository getGsonBBSRepo1() {
Repository gsonBBSRepo1 = new Repository();
gsonBBSRepo1.setId(1L);
gsonBBSRepo1.setName("repoName1");
Project project1 = new Project();
project1.setName("projectName1");
project1.setKey("projectKey1");
project1.setId(2L);
gsonBBSRepo1.setProject(project1);
gsonBBSRepo1.setSlug("repo-slug-1");
return gsonBBSRepo1;
}
Aggregations