Search in sources :

Example 6 with CeTaskMessageDto

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

the class AnalysisStatusActionTest method createTaskMessage.

private CeTaskMessageDto createTaskMessage(CeActivityDto activity, String warning, CeTaskMessageType messageType) {
    CeTaskMessageDto ceTaskMessageDto = new CeTaskMessageDto().setUuid("m-uuid-" + counter++).setTaskUuid(activity.getUuid()).setMessage(warning).setType(messageType).setCreatedAt(counter);
    db.getDbClient().ceTaskMessageDao().insert(db.getSession(), ceTaskMessageDto);
    db.commit();
    return ceTaskMessageDto;
}
Also used : CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto)

Example 7 with CeTaskMessageDto

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

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

the class DismissAnalysisWarningActionTest method returns_400_if_warning_is_not_dismissable.

@Test
public void returns_400_if_warning_is_not_dismissable() {
    UserDto user = db.users().insertUser();
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn(user).addProjectPermission(UserRole.USER, project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessage = createTaskMessage(activity, "generic warning");
    TestRequest request = underTest.newRequest().setParam("component", project.getKey()).setParam("warning", taskMessage.getUuid());
    assertThrows(format("Message '%s' cannot be dismissed.", taskMessage.getUuid()), IllegalArgumentException.class, request::execute);
    assertThat(db.countRowsOfTable("USER_DISMISSED_MESSAGES")).isZero();
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) UserDto(org.sonar.db.user.UserDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 9 with CeTaskMessageDto

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

the class DismissAnalysisWarningActionTest method return_204_on_success.

@Test
public void return_204_on_success() {
    UserDto user = db.users().insertUser();
    ComponentDto project = db.components().insertPrivateProject();
    userSession.logIn(user).addProjectPermission(UserRole.USER, project);
    SnapshotDto analysis = db.components().insertSnapshot(project);
    CeActivityDto activity = insertActivity("task-uuid" + counter++, project, SUCCESS, analysis, REPORT);
    CeTaskMessageDto taskMessageDismissible = createTaskMessage(activity, "dismissable warning", CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE);
    TestResponse response = underTest.newRequest().setParam("component", project.getKey()).setParam("warning", taskMessageDismissible.getUuid()).execute();
    assertThat(response.getStatus()).isEqualTo(204);
    assertThat(db.select("select * from user_dismissed_messages")).extracting("USER_UUID", "PROJECT_UUID", "MESSAGE_TYPE").containsExactly(tuple(userSession.getUuid(), project.uuid(), CeTaskMessageType.SUGGEST_DEVELOPER_EDITION_UPGRADE.name()));
}
Also used : CeActivityDto(org.sonar.db.ce.CeActivityDto) TestResponse(org.sonar.server.ws.TestResponse) UserDto(org.sonar.db.user.UserDto) SnapshotDto(org.sonar.db.component.SnapshotDto) CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 10 with CeTaskMessageDto

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

the class UpgradeSuggestionsCleanerTest method insertCeTaskMessage.

private void insertCeTaskMessage(String uuid, CeTaskMessageType messageType, String msg) {
    CeTaskMessageDto dto = new CeTaskMessageDto().setUuid(uuid).setMessage(msg).setType(messageType).setTaskUuid(TASK_UUID);
    dbTester.getDbClient().ceTaskMessageDao().insert(dbTester.getSession(), dto);
    dbTester.getSession().commit();
}
Also used : CeTaskMessageDto(org.sonar.db.ce.CeTaskMessageDto)

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