Search in sources :

Example 46 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionMediumTest method issue_with_comments.

@Test
public void issue_with_comments() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("john").setName("John"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2");
    db.issueDao().insert(session, issue);
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCD").setChangeData("*My comment*").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("john").setCreatedAt(DateUtils.parseDateTime("2014-09-09T12:00:00+0000").getTime()));
    tester.get(IssueChangeDao.class).insert(session, new IssueChangeDto().setIssueKey(issue.getKey()).setKey("COMMENT-ABCE").setChangeData("Another comment").setChangeType(IssueChangeDto.TYPE_COMMENT).setUserLogin("fabrice").setCreatedAt(DateUtils.parseDateTime("2014-09-10T12:00:00+0000").getTime()));
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john");
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("additionalFields", "comments,users").execute();
    result.assertJson(this.getClass(), "issue_with_comments.json");
}
Also used : IssueChangeDto(org.sonar.db.issue.IssueChangeDto) WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) IssueChangeDao(org.sonar.db.issue.IssueChangeDao) Test(org.junit.Test)

Example 47 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionMediumTest method load_additional_fields_with_issue_admin_permission.

@Test
public void load_additional_fields_with_issue_admin_permission() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com"));
    db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java"));
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js"));
    setProjectPermission(project, USER, ISSUE_ADMIN);
    IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2").setAuthorLogin("John").setAssignee("simon");
    db.issueDao().insert(session, issue);
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("additionalFields", "_all").execute();
    result.assertJson(this.getClass(), "load_additional_fields_with_issue_admin_permission.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Test(org.junit.Test)

Example 48 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionMediumTest method filter_by_assigned_to_me.

@Test
public void filter_by_assigned_to_me() throws Exception {
    db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com"));
    ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY"));
    setDefaultProjectPermission(project);
    ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY"));
    RuleDto rule = newRule();
    IssueDto issue1 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2").setSeverity("MAJOR").setAssignee("john");
    IssueDto issue2 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("7b112bd4-b650-4037-80bc-82fd47d4eac2").setSeverity("MAJOR").setAssignee("alice");
    IssueDto issue3 = IssueTesting.newDto(rule, file, project).setIssueCreationDate(DateUtils.parseDate("2014-09-04")).setIssueUpdateDate(DateUtils.parseDate("2017-12-04")).setEffort(10L).setStatus("OPEN").setKee("82fd47d4-4037-b650-80bc-7b112bd4eac2").setSeverity("MAJOR");
    db.issueDao().insert(session, issue1, issue2, issue3);
    session.commit();
    IssueIndexer r = tester.get(IssueIndexer.class);
    r.indexOnStartup(r.getIndexTypes());
    userSessionRule.logIn("john");
    wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam("resolved", "false").setParam("assignees", "__me__").setParam(WebService.Param.FACETS, "assignees,assigned_to_me").execute().assertJson(this.getClass(), "filter_by_assigned_to_me.json");
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) UserDto(org.sonar.db.user.UserDto) ComponentDto(org.sonar.db.component.ComponentDto) IssueDto(org.sonar.db.issue.IssueDto) IssueIndexer(org.sonar.server.issue.index.IssueIndexer) Test(org.junit.Test)

Example 49 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class CreateActionTest method setUp.

@Before
public void setUp() {
    ws = new WsTester(new CustomMeasuresWs(new CreateAction(dbClient, userSession, System2.INSTANCE, new CustomMeasureValidator(newFullTypeValidations()), new CustomMeasureJsonWriter(new UserJsonWriter(userSession)), new ComponentFinder(dbClient))));
    db.getDbClient().userDao().insert(dbSession, new UserDto().setLogin("login").setName("Login").setEmail("login@login.com").setActive(true));
    dbSession.commit();
    userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
}
Also used : ComponentFinder(org.sonar.server.component.ComponentFinder) WsTester(org.sonar.server.ws.WsTester) UserJsonWriter(org.sonar.server.user.ws.UserJsonWriter) UserDto(org.sonar.db.user.UserDto) Before(org.junit.Before)

Example 50 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class OrganizationCreationImplTest method createForUser_does_not_create_any_group.

@Test
public void createForUser_does_not_create_any_group() throws OrganizationCreation.KeyConflictException {
    UserDto user = dbTester.users().insertUser(dto -> dto.setLogin(A_LOGIN).setName(A_NAME));
    when(organizationValidation.generateKeyFrom(A_LOGIN)).thenReturn(SLUG_OF_A_LOGIN);
    mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
    enableCreatePersonalOrg(true);
    underTest.createForUser(dbSession, user);
    OrganizationDto organization = dbClient.organizationDao().selectByKey(dbSession, SLUG_OF_A_LOGIN).get();
    assertThat(dbClient.groupDao().selectByOrganizationUuid(dbSession, organization.getUuid())).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41