Search in sources :

Example 1 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class ActivityActionTest method insertMessages.

private void insertMessages(String taskUuid, int messageCount) {
    IntStream.range(0, messageCount).forEach(i -> db.getDbClient().ceTaskMessageDao().insert(db.getSession(), new CeTaskMessageDto().setUuid("uuid_" + taskUuid + "_" + i).setTaskUuid(taskUuid).setMessage("m_" + taskUuid + "_" + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(taskUuid.hashCode() + i)));
    db.commit();
}
Also used : CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto)

Example 2 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class ComponentActionTest method populates_warning_count_of_activities_but_not_warnings.

@Test
public void populates_warning_count_of_activities_but_not_warnings() {
    ComponentDto privateProject = db.components().insertPrivateProject();
    userSession.addProjectPermission(UserRole.USER, privateProject);
    SnapshotDto analysis = db.components().insertSnapshot(privateProject);
    CeActivityDto activity = insertActivity("Branch", privateProject, SUCCESS, analysis);
    int messageCount = 1 + new Random().nextInt(10);
    IntStream.range(0, messageCount).forEach(i -> db.getDbClient().ceTaskMessageDao().insert(db.getSession(), new CeTaskMessageDto().setUuid("uuid_" + i).setTaskUuid(activity.getUuid()).setMessage("m_" + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(i)));
    db.commit();
    Ce.ComponentResponse response = ws.newRequest().setParam(PARAM_COMPONENT, privateProject.getKey()).executeProtobuf(Ce.ComponentResponse.class);
    assertThat(response.hasCurrent()).isTrue();
    assertThat(response.getCurrent()).extracting(Ce.Task::getWarningCount, Ce.Task::getWarningsList).containsOnly(messageCount, emptyList());
}
Also used : Ce(org.sonarqube.ws.Ce) CeActivityDto(org.sonar.db.ce.CeActivityDto) Random(java.util.Random) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class TaskActionTest method insertWarning.

private CeTaskMessageDto insertWarning(CeActivityDto task, int i) {
    CeTaskMessageDto res = new CeTaskMessageDto().setUuid(UuidFactoryFast.getInstance().create()).setTaskUuid(task.getUuid()).setMessage("msg_" + task.getUuid() + "_" + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(task.getUuid().hashCode() + i);
    db.getDbClient().ceTaskMessageDao().insert(db.getSession(), res);
    db.getSession().commit();
    return res;
}
Also used : CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto)

Example 4 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto in project sonarqube by SonarSource.

the class TaskActionTest method no_warning_detail_on_task_in_queue.

@Test
public void no_warning_detail_on_task_in_queue() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).setRoot();
    CeQueueDto queueDto = createAndPersistQueueTask(null, user);
    IntStream.range(0, 1 + new Random().nextInt(5)).forEach(i -> db.getDbClient().ceTaskMessageDao().insert(db.getSession(), new CeTaskMessageDto().setUuid("u_" + i).setTaskUuid(queueDto.getUuid()).setMessage("m_" + i).setType(CeTaskMessageType.GENERIC).setCreatedAt(queueDto.getUuid().hashCode() + i)));
    db.commit();
    Ce.TaskResponse taskResponse = ws.newRequest().setParam("id", SOME_TASK_UUID).executeProtobuf(Ce.TaskResponse.class);
    Ce.Task task = taskResponse.getTask();
    assertThat(task.getWarningCount()).isZero();
    assertThat(task.getWarningsList()).isEmpty();
}
Also used : Ce(org.sonarqube.ws.Ce) Random(java.util.Random) UserDto(org.sonar.db.user.UserDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) CeQueueDto(org.sonar.db.ce.CeQueueDto) Test(org.junit.Test)

Example 5 with CeTaskMessageDto

use of org.sonar.db.ce.CeTaskMessageDto 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)

Aggregations

CeTaskMessageDto (org.sonar.db.ce.CeTaskMessageDto)17 Test (org.junit.Test)11 CeActivityDto (org.sonar.db.ce.CeActivityDto)10 ComponentDto (org.sonar.db.component.ComponentDto)10 SnapshotDto (org.sonar.db.component.SnapshotDto)10 UserDto (org.sonar.db.user.UserDto)6 Ce (org.sonarqube.ws.Ce)6 Random (java.util.Random)3 DbSession (org.sonar.db.DbSession)2 ProjectDto (org.sonar.db.project.ProjectDto)2 UserDismissedMessageDto (org.sonar.db.user.UserDismissedMessageDto)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1 UTC (java.time.ZoneOffset.UTC)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1