Search in sources :

Example 96 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ComponentActionTest method branch_in_activity.

@Test
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));
    SnapshotDto analysis = db.components().insertSnapshot(branch);
    CeActivityDto activity = insertActivity("T1", project, SUCCESS, analysis);
    insertCharacteristic(activity, BRANCH_KEY, branch.getBranch());
    insertCharacteristic(activity, BRANCH_TYPE_KEY, BRANCH.name());
    Ce.ComponentResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.ComponentResponse.class);
    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());
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 97 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class ComponentCleanerServiceTest method insertProjectData.

private DbData insertProjectData() {
    ComponentDto componentDto = db.components().insertPublicProject();
    ProjectDto project = dbClient.projectDao().selectByUuid(dbSession, componentDto.uuid()).get();
    BranchDto branch = dbClient.branchDao().selectByUuid(dbSession, project.getUuid()).get();
    RuleDefinitionDto rule = db.rules().insert();
    IssueDto issue = db.issues().insert(rule, project, componentDto);
    SnapshotDto analysis = db.components().insertSnapshot(componentDto);
    mockResourceTypeAsValidProject();
    return new DbData(project, branch, analysis, issue);
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) BranchDto(org.sonar.db.component.BranchDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto)

Example 98 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method return_warnings_per_branch.

@Test
public void return_warnings_per_branch() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto warningInMainMessage = createTaskMessage(activity, WARNING_IN_MAIN);
    ComponentDto branchWithWarning = db.components().insertProjectBranch(project, b -> b.setKey(BRANCH_WITH_WARNING));
    SnapshotDto branchAnalysis = db.components().insertSnapshot(branchWithWarning);
    CeActivityDto branchActivity = insertActivity("task-uuid" + counter++, branchWithWarning, SUCCESS, branchAnalysis, REPORT);
    CeTaskMessageDto warningInBranchMessage = createTaskMessage(branchActivity, WARNING_IN_BRANCH);
    ComponentDto branchWithoutWarning = db.components().insertProjectBranch(project, b -> b.setKey(BRANCH_WITHOUT_WARNING));
    SnapshotDto branchWithoutWarningAnalysis = db.components().insertSnapshot(branchWithoutWarning);
    insertActivity("task-uuid" + counter++, branchWithoutWarning, SUCCESS, branchWithoutWarningAnalysis, REPORT);
    ComponentDto pullRequest = db.components().insertProjectBranch(project, b -> {
        b.setBranchType(BranchType.PULL_REQUEST);
        b.setKey(PULL_REQUEST);
    });
    SnapshotDto prAnalysis = db.components().insertSnapshot(pullRequest);
    CeActivityDto prActivity = insertActivity("task-uuid" + counter++, pullRequest, SUCCESS, prAnalysis, REPORT);
    CeTaskMessageDto warningInPrMessage = createTaskMessage(prActivity, WARNING_IN_PR);
    Ce.AnalysisStatusWsResponse responseForMain = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(responseForMain.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(warningInMainMessage.getUuid(), WARNING_IN_MAIN, false));
    Ce.AnalysisStatusWsResponse responseForBranchWithWarning = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_BRANCH, BRANCH_WITH_WARNING).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(responseForBranchWithWarning.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(warningInBranchMessage.getUuid(), WARNING_IN_BRANCH, false));
    Ce.AnalysisStatusWsResponse responseForBranchWithoutWarning = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_BRANCH, BRANCH_WITHOUT_WARNING).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(responseForBranchWithoutWarning.getComponent().getWarningsList()).isEmpty();
    Ce.AnalysisStatusWsResponse responseForPr = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_PULL_REQUEST, PULL_REQUEST).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(responseForPr.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(warningInPrMessage.getUuid(), WARNING_IN_PR, false));
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 99 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method return_warnings_for_last_analysis_of_branch.

@Test
public void return_warnings_for_last_analysis_of_branch() {
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn().setSystemAdministrator().addProjectPermission(UserRole.USER, project);
    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey(BRANCH_WITH_WARNING));
    SnapshotDto analysis = db.components().insertSnapshot(branch);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, branch, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessage = createTaskMessage(activity, WARNING_IN_BRANCH);
    Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_BRANCH, BRANCH_WITH_WARNING).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response.getComponent().getWarningsList()).extracting(Warning::getKey, Warning::getMessage, Warning::getDismissable).containsExactly(tuple(taskMessage.getUuid(), WARNING_IN_BRANCH, false));
    SnapshotDto analysis2 = db.components().insertSnapshot(branch);
    insertActivity("task-uuid" + counter++, branch, SUCCESS, analysis2, REPORT);
    insertActivity("task-uuid" + counter++, branch, SUCCESS, null, "PROJECT_EXPORT");
    Ce.AnalysisStatusWsResponse response2 = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).setParam(PARAM_BRANCH, BRANCH_WITH_WARNING).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response2.getComponent().getWarningsList()).isEmpty();
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 100 with SnapshotDto

use of org.sonar.db.component.SnapshotDto in project sonarqube by SonarSource.

the class AnalysisStatusActionTest method allows_unauthenticated_access.

@Test
public void allows_unauthenticated_access() {
    ComponentDto project = db.components().insertPublicProject();
    userSession.registerComponents(project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    createTaskMessage(activity, WARNING_IN_MAIN);
    createTaskMessage(activity, "Dismissible warning", CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    Ce.AnalysisStatusWsResponse response = ws.newRequest().setParam(PARAM_COMPONENT, project.getKey()).executeProtobuf(Ce.AnalysisStatusWsResponse.class);
    assertThat(response.getComponent().getWarningsList()).hasSize(2);
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) SnapshotDto(org.sonar.db.component.SnapshotDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Aggregations

SnapshotDto (org.sonar.db.component.SnapshotDto)326 Test (org.junit.Test)257 ComponentDto (org.sonar.db.component.ComponentDto)219 MetricDto (org.sonar.db.metric.MetricDto)54 TestComputationStepContext (org.sonar.ce.task.step.TestComputationStepContext)31 EventDto (org.sonar.db.event.EventDto)30 ProjectDto (org.sonar.db.project.ProjectDto)27 DbSession (org.sonar.db.DbSession)26 SnapshotTesting.newAnalysis (org.sonar.db.component.SnapshotTesting.newAnalysis)21 BranchDto (org.sonar.db.component.BranchDto)20 SearchEventsWsResponse (org.sonarqube.ws.Developers.SearchEventsWsResponse)20 MetricTesting.newMetricDto (org.sonar.db.metric.MetricTesting.newMetricDto)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 DbClient (org.sonar.db.DbClient)14 NotFoundException (org.sonar.server.exceptions.NotFoundException)14 List (java.util.List)13 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 Rule (org.junit.Rule)13 UserRole (org.sonar.api.web.UserRole)13 DbTester (org.sonar.db.DbTester)13