public class StatusActionIT {
- private static final String SOME_UUID = "some uuid";
private static final String ID_PARAM = "id";
private static final String KEY_PARAM = "key";
- private static final String SOME_KEY = "some key";
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@Before
public void setUp() throws Exception {
- project = insertProject(SOME_UUID, SOME_KEY);
+ project = db.components().insertPrivateProject().getProjectDto();
+
logInAsProjectAdministrator("user");
when(config.get("sonar.path.data")).thenReturn(Optional.of("data"));
public void fails_with_BRE_if_both_params_are_provided() {
assertThatThrownBy(() -> {
underTest.newRequest()
- .setParam(ID_PARAM, SOME_UUID).setParam(KEY_PARAM, SOME_KEY)
+ .setParam(ID_PARAM, project.getUuid()).setParam(KEY_PARAM, project.getKey())
.execute();
})
.isInstanceOf(BadRequestException.class)
@Test
public void project_without_snapshot_can_be_imported_but_not_exported() {
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
insertSnapshot(project, false);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
insertSnapshot(project, false);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
@Test
public void exportedDump_field_contains_absolute_path_if_file_exists_and_is_regular_file() throws IOException {
- final String exportDumpFilePath = ensureDumpFileExists(SOME_KEY, false);
+ final String exportDumpFilePath = ensureDumpFileExists(project.getKey(), false);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
@Test
public void exportedDump_field_contains_absolute_path_if_file_exists_and_is_link() throws IOException {
- final String exportDumpFilePath = ensureDumpFileExists(SOME_KEY, false);
+ final String exportDumpFilePath = ensureDumpFileExists(project.getKey(), false);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
Files.createDirectories(Paths.get(exportDirectoryPathname));
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
@Test
public void dumpToImport_field_contains_absolute_path_if_file_exists_and_is_regular_file() throws IOException {
- final String importDumpFilePath = ensureDumpFileExists(SOME_KEY, true);
+ final String importDumpFilePath = ensureDumpFileExists(project.getKey(), true);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
@Test
public void dumpToImport_field_contains_absolute_path_if_file_exists_and_is_link() throws IOException {
- final String importDumpFilePath = ensureDumpFileExists(SOME_KEY, true);
+ final String importDumpFilePath = ensureDumpFileExists(project.getKey(), true);
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
Files.createDirectories(Paths.get(importDirectoryPathname));
String response = underTest.newRequest()
- .setParam(KEY_PARAM, SOME_KEY)
+ .setParam(KEY_PARAM, project.getKey())
.execute()
.getInput();
.isInstanceOf(NotFoundException.class);
}
- private ProjectDto insertProject(String uuid, String key) {
- return db.components().insertPrivateProject(c -> c.setBranchUuid(uuid).setUuid(uuid).setKey(key)).getProjectDto();
- }
private void insertSnapshot(ProjectDto projectDto, boolean last) {
- dbClient.snapshotDao().insert(dbSession, SnapshotTesting.newAnalysis(projectDto.getUuid()).setLast(last));
+ db.components().insertSnapshot(projectDto, snapshotDto -> snapshotDto.setLast(last));
dbSession.commit();
}
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.project.ProjectDto;
import org.sonar.server.component.ComponentFinder;
import org.sonar.server.user.UserSession;
try (DbSession dbSession = dbClient.openSession(false)) {
ProjectDto project = getProject(dbSession, uuid, key);
+ BranchDto mainBranch = componentFinder.getMainBranch(dbSession, project);
userSession.checkEntityPermission(UserRole.ADMIN, project);
WsResponse wsResponse = new WsResponse();
checkDumps(project, wsResponse);
- SnapshotsStatus snapshots = checkSnapshots(dbSession, project);
+ SnapshotsStatus snapshots = checkSnapshots(dbSession, mainBranch);
if (snapshots.hasLast) {
wsResponse.setCanBeExported();
} else if (!snapshots.hasAny) {
}
}
- private SnapshotsStatus checkSnapshots(DbSession dbSession, ProjectDto project) throws SQLException {
+ private SnapshotsStatus checkSnapshots(DbSession dbSession, BranchDto mainBranch) throws SQLException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
" group by" +
" islast";
stmt = dbClient.getMyBatis().newScrollingSelectStatement(dbSession, sql);
- stmt.setString(1, project.getUuid());
+ stmt.setString(1, mainBranch.getUuid());
rs = stmt.executeQuery();
SnapshotsStatus res = new SnapshotsStatus();
while (rs.next()) {