OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").addProjectUuidPermissions(SCAN_EXECUTION, project.projectUuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(SCAN_EXECUTION, project.projectUuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
dbClient.organizationDao().insert(dbSession, organizationDto);
// No snapshot attached on the project -> provisioned project
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
// No module properties
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, subModule);
// Sub module properties
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(module.getId()));
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, subModule);
// Sub module properties
// No module property
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, subModule);
// No sub module property
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId()));
ComponentDto subModule = ComponentTesting.newModuleDto(module);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, subModule);
// No sub module property
@Test
public void fail_when_no_browse_permission_and_no_scan_permission() {
- userSessionRule.login("john").setGlobalPermissions();
+ userSessionRule.logIn("john").setGlobalPermissions();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.projectUuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.projectUuid());
thrown.expect(ForbiddenException.class);
thrown.expectMessage("You're only authorized to execute a local (preview) SonarQube analysis without pushing the results to the SonarQube server. " +
dbClient.componentDao().insert(dbSession, project);
dbSession.commit();
- userSessionRule.login("john").addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.projectUuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.projectUuid());
thrown.expect(ForbiddenException.class);
thrown.expectMessage("You don't have the required permissions to access this project. Please contact your SonarQube administrator.");
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto();
dbClient.organizationDao().insert(dbSession, organizationDto);
ComponentDto project = ComponentTesting.newProjectDto(organizationDto);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, project);
addDefaultProfile();
tester.get(FileSourceDao.class).insert(newFileSourceDto(projectFile).setSrcHash("123456").setRevision("987654321"));
ComponentDto module = ComponentTesting.newModuleDto(project);
- userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSessionRule.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
dbClient.componentDao().insert(dbSession, module);
// File on module
es.putDocuments(UserIndexDefinition.INDEX, UserIndexDefinition.TYPE_USER,
new UserDoc().setLogin("ada.lovelace").setName("Ada Lovelace").setActive(false),
new UserDoc().setLogin("grace.hopper").setName("Grace Hopper").setActive(true));
- userSessionRule.login("sonarqtech");
+ userSessionRule.logIn("sonarqtech");
WsTester.TestRequest request = tester.newGetRequest("batch", "users").setParam("logins", "ada.lovelace,grace.hopper");
String view_uuid = "VIEW_1";
dbTester.components().insertView(dbTester.getDefaultOrganization(), view_uuid);
insertActivity("T1", view_uuid, CeActivityDto.Status.SUCCESS);
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, view_uuid);
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, view_uuid);
ActivityResponse result = call(ws.newRequest().setParam(Param.TEXT_QUERY, "T1"));
public void status_for_a_project_as_project_admin() {
String projectUuid = "project-uuid";
String anotherProjectUuid = "another-project-uuid";
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, projectUuid);
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, projectUuid);
OrganizationDto organizationDto = db.organizations().insert();
componentDb.insertComponent(newProjectDto(organizationDto, projectUuid));
componentDb.insertComponent(newProjectDto(organizationDto, anotherProjectUuid));
@Test
public void task_is_in_queue() throws Exception {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType(CeTaskTypes.REPORT);
@Test
public void task_is_archived() throws Exception {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID);
persist(activityDto);
@Test
public void return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_set() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID)
.setErrorMessage("error msg")
@Test
public void do_not_return_stacktrace_of_failed_activity_with_stacktrace_when_additionalField_is_not_set() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID)
.setErrorMessage("error msg")
@Test
public void return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_set() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
String scannerContext = "this is some scanner context, yeah!";
persist(createActivityDto(SOME_TASK_UUID));
@Test
public void do_not_return_scannerContext_of_activity_with_scannerContext_when_additionalField_is_not_set() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
String scannerContext = "this is some scanner context, yeah!";
persist(createActivityDto(SOME_TASK_UUID));
@Test
public void do_not_return_stacktrace_of_failed_activity_without_stacktrace() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID)
.setErrorMessage("error msg");
@Test
public void task_not_found() throws Exception {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
expectedException.expect(NotFoundException.class);
ws.newRequest()
@Test
public void not_fail_on_queue_task_not_linked_on_project_with_system_admin_permissions() {
- userSession.login("john").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(SYSTEM_ADMIN);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType("fake");
@Test
public void not_fail_on_queue_task_not_linked_on_project_with_global_scan_permissions() {
- userSession.login("john").setGlobalPermissions(SCAN_EXECUTION);
+ userSession.logIn("john").setGlobalPermissions(SCAN_EXECUTION);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType("fake");
@Test
public void fail_on_queue_task_not_linked_on_project_if_not_admin_nor_scan_permission() {
- userSession.login("john").setGlobalPermissions(PROVISIONING);
+ userSession.logIn("john").setGlobalPermissions(PROVISIONING);
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType("fake");
@Test
public void not_fail_on_queue_task_linked_on_project_with_project_scan_permission() {
- userSession.login("john").addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
CeQueueDto queueDto = new CeQueueDto();
queueDto.setTaskType("fake");
@Test
public void not_fail_on_archived_task_linked_on_project_with_project_scan_permission() throws Exception {
- userSession.login("john").addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(SCAN_EXECUTION, project.uuid());
CeActivityDto activityDto = createActivityDto(SOME_TASK_UUID)
.setComponentUuid(project.uuid());
dbSession.commit();
- userSession.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
underTest.updateKey(dbSession, project, "sample2:root");
dbSession.commit();
ComponentDto file = ComponentTesting.newFileDto(module, null).setKey("sample:root:module:src/File.xoo");
dbClient.componentDao().insert(dbSession, file);
dbSession.commit();
- userSession.login("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
underTest.updateKey(dbSession, module, "sample:root2:module");
dbSession.commit();
dbSession.commit();
- userSession.login("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(UserRole.ADMIN, provisionedProject.uuid());
underTest.updateKey(dbSession, provisionedProject, "provisionedProject2");
dbSession.commit();
expectedException.expect(ForbiddenException.class);
ComponentDto project = insertSampleRootProject();
- userSession.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
underTest.updateKey(dbSession, project, "sample2:root");
}
@Test
public void should_find_project_for_which_the_user_has_direct_permission() {
UserDto user = newUserDto();
- userSession.login(user);
+ userSession.logIn(user);
ComponentDto project = newProject("sonarqube", "Quality Product");
indexer.index(project);
@Test
public void should_find_project_for_which_the_user_has_indirect_permission_through_group() {
GroupDto group = newGroupDto();
- userSession.login().setGroups(group);
+ userSession.logIn().setGroups(group);
ComponentDto project = newProject("sonarqube", "Quality Product");
indexer.index(project);
insertComponentsAndAnalysis();
dbTester.commit();
- userSessionRule.login("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
+ userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
WsTester.TestRequest request = wsTester.newGetRequest("api/components", "app").setParam("uuid", FILE_UUID);
request.execute().assertJson(getClass(), "app.json");
}
dbTester.commit();
userSessionRule
- .login("john")
+ .logIn("john")
.addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
WsTester.TestRequest request = wsTester.newGetRequest("api/components", "app").setParam("uuid", FILE_UUID);
request.execute().assertJson(getClass(), "app_with_measures.json");
insertFileMeasure(metricsByKey.get(COVERAGE_KEY).getId(), 95.4, null);
dbTester.commit();
- userSessionRule.login("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
+ userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, PROJECT_UUID, FILE_UUID);
WsTester.TestRequest request = wsTester.newGetRequest("api/components", "app").setParam("uuid", FILE_UUID);
request.execute().assertJson(getClass(), "app_with_ut_measure.json");
}
ws = new WsActionTester(new SearchAction(db.getDbClient(), resourceTypes, i18n, userSession, languages, defaultOrganizationProvider));
user = db.users().insertUser("john");
- userSession.login(user);
+ userSession.logIn(user);
}
@Test
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(23);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(23);
@Rule
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings()));
@Rule
.setUuid(Uuids.UUID_EXAMPLE_03)
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_003)
.setName("My Project 3"));
- userSession.login().setUserId(23);
+ userSession.logIn().setUserId(23);
addFavourite(project1);
dbSession.commit();
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setRoot().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setRoot().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
@Rule
public DbTester db = DbTester.create(System2.INSTANCE);
@Before
public void setUp() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
userSession.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
ws = new WsActionTester(new TreeAction(dbClient, new ComponentFinder(dbClient), resourceTypes, userSession, Mockito.mock(I18n.class)));
resourceTypes.setChildrenQualifiers(Qualifiers.MODULE, Qualifiers.FILE, Qualifiers.DIRECTORY);
@Test
public void json_example() throws IOException {
ComponentDto project = initJsonExampleComponents();
- userSession.login().addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
String response = ws.newRequest()
.setParam(PARAM_BASE_COMPONENT_ID, project.uuid())
@Test
public void fail_when_not_enough_privileges() {
expectedException.expect(ForbiddenException.class);
- userSession.anonymous().login()
+ userSession.anonymous().logIn()
.addProjectUuidPermissions(UserRole.CODEVIEWER, "project-uuid");
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid"));
db.commit();
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
}
@Test
public void fail_when_no_browse_permission_on_the_project() {
insertProject();
- userSession.login();
+ userSession.logIn();
userSession.addProjectUuidPermissions(UserRole.ADMIN, PROJECT_UUID);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_when_component_is_not_found() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
private ComponentDto insertProjectAndPermissions() {
userSession
- .login()
+ .logIn()
.setUserId(USER_ID)
.addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
@Test
public void fail_when_component_is_not_found() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
}
private ComponentDto insertProjectAndPermissions() {
- userSession.login().setUserId(USER_ID);
+ userSession.logIn().setUserId(USER_ID);
return insertProject();
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(USER_ID);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(USER_ID);
@Rule
public DbTester db = DbTester.create();
private DbClient dbClient = db.getDbClient();
public ExpectedException thrown = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login("arthur");
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn("arthur");
private ComponentDto project = newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setKey(PROJECT_KEY);
private IssueDto issue = newDto(newXooX1().setId(10), newFileDto(project, null), project).setKee(ISSUE_KEY);
@Test
public void doest_not_return_assign_to_me_action_when_issue_already_assigned_to_user() {
- userSession.login("julien");
+ userSession.logIn("julien");
IssueDto issue = newDto(newXooX1().setId(10), newFileDto(project, null), project).setKee(ISSUE_KEY).setAssignee("julien");
assertThat(underTest.listAvailableActions(issue)).doesNotContain("assign_to_me");
}
RuleDto rule = newRule();
ComponentDto project = newProject();
ComponentDto file = newFile(project);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
RuleDto rule = newRule();
ComponentDto project = newProject();
ComponentDto file = newFile(project);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project).setAssignee("perceval"));
RuleDto rule = newRule();
ComponentDto project = newProject();
ComponentDto file = newFile(project);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
RuleDto rule = newRule();
ComponentDto project = newProject();
ComponentDto file = newFile(project);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, project.uuid());
IssueDto issue = saveIssue(IssueTesting.newDto(rule, file, project));
ComponentDto project = ComponentTesting.newProjectDto(organization);
tester.get(ComponentDao.class).insert(session, project);
- userSessionRule.login("admin").addProjectPermissions(UserRole.USER, project.key()).setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("admin").addProjectPermissions(UserRole.USER, project.key()).setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
session.commit();
// project can be seen by group "anyone"
GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(project),
GroupIdOrAnyone.forAnyone(organization.getUuid()));
tester.get(PermissionUpdater.class).apply(session, asList(permissionChange));
- userSessionRule.login();
+ userSessionRule.logIn();
return project;
}
}
private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
- userSession.login(USER_LOGIN)
+ userSession.logIn(USER_LOGIN)
.addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
.addProjectUuidPermissions(USER, projectUuid);
}
}
private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
- userSession.login(USER_LOGIN)
+ userSession.logIn(USER_LOGIN)
.addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
.addProjectUuidPermissions(USER, projectUuid);
}
@Test
public void execute() {
- userSession.login("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
issue.setStatus(Issue.STATUS_RESOLVED);
issue.setResolution(Issue.RESOLUTION_FIXED);
@Test
public void does_not_execute_if_transition_is_not_available() {
- userSession.login("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.projectUuid());
issue.setStatus(Issue.STATUS_CLOSED);
action.execute(ImmutableMap.of("transition", "reopen"), context);
@Test
public void list_transitions() throws Exception {
IssueDto issue = newIssue().setStatus(STATUS_OPEN).setResolution(null);
- userSession.login("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issue.getProjectUuid());
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
@Test
public void list_transitions_returns_only_transitions_that_do_not_requires_issue_admin_permission() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
IssueDto issue = newIssue().setStatus(STATUS_OPEN).setResolution(null);
List<Transition> result = underTest.listTransitions(issue.toDefaultIssue());
ComponentDto project = newProjectDto(newOrganizationDto());
ComponentDto file = newFileDto(project, null);
IssueDoc issue = IssueDocTesting.newDoc("ISSUE1", file)
- .setEffort(100L);
+ .setEffort(100L);
indexIssues(issue);
Issue loaded = getByKey(issue.key());
ComponentDto project = newProjectDto(newOrganizationDto());
indexIssues(
- IssueDocTesting.newDoc("1", newFileDto(project, null)),
- IssueDocTesting.newDoc("2", newFileDto(project, null)));
+ IssueDocTesting.newDoc("1", newFileDto(project, null)),
+ IssueDocTesting.newDoc("2", newFileDto(project, null)));
assertThat(underTest.search(IssueQuery.builder().issueKeys(newArrayList("1", "2")).build(), new SearchOptions()).getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder().issueKeys(newArrayList("1")).build(), new SearchOptions()).getDocs()).hasSize(1);
ComponentDto subModule = ComponentTesting.newModuleDto(module);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", project),
- IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)),
- IssueDocTesting.newDoc("ISSUE3", module),
- IssueDocTesting.newDoc("ISSUE4", newFileDto(module, null)),
- IssueDocTesting.newDoc("ISSUE5", subModule),
- IssueDocTesting.newDoc("ISSUE6", newFileDto(subModule, null)));
+ IssueDocTesting.newDoc("ISSUE1", project),
+ IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)),
+ IssueDocTesting.newDoc("ISSUE3", module),
+ IssueDocTesting.newDoc("ISSUE4", newFileDto(module, null)),
+ IssueDocTesting.newDoc("ISSUE5", subModule),
+ IssueDocTesting.newDoc("ISSUE6", newFileDto(subModule, null)));
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
ComponentDto project2 = newProjectDto(organizationDto, "EFGH");
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", newFileDto(project, null)),
- IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)),
- IssueDocTesting.newDoc("ISSUE3", newFileDto(project2, null)));
+ IssueDocTesting.newDoc("ISSUE1", newFileDto(project, null)),
+ IssueDocTesting.newDoc("ISSUE2", newFileDto(project, null)),
+ IssueDocTesting.newDoc("ISSUE3", newFileDto(project2, null)));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("projectUuids")));
assertThat(result.getFacets().getNames()).containsOnly("projectUuids");
ComponentDto file = newFileDto(subModule, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE3", module),
- IssueDocTesting.newDoc("ISSUE5", subModule),
- IssueDocTesting.newDoc("ISSUE2", file));
+ IssueDocTesting.newDoc("ISSUE3", module),
+ IssueDocTesting.newDoc("ISSUE5", subModule),
+ IssueDocTesting.newDoc("ISSUE2", file));
assertThat(
- underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(file.uuid())).build(), new SearchOptions())
- .getDocs())
- .isEmpty();
+ underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(file.uuid())).build(), new SearchOptions())
+ .getDocs())
+ .isEmpty();
assertThat(
- underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions())
- .getDocs())
- .hasSize(1);
+ underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(module.uuid())).build(), new SearchOptions())
+ .getDocs())
+ .hasSize(1);
assertThat(
- underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions())
- .getDocs())
- .hasSize(2);
+ underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(subModule.uuid())).build(), new SearchOptions())
+ .getDocs())
+ .hasSize(2);
assertThat(
- underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(project.uuid())).build(), new SearchOptions())
- .getDocs())
- .isEmpty();
+ underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList(project.uuid())).build(), new SearchOptions())
+ .getDocs())
+ .isEmpty();
assertThat(
- underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs())
+ underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).moduleUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs())
.isEmpty();
}
indexView(view, newArrayList(project.uuid()));
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", project),
- IssueDocTesting.newDoc("ISSUE2", file1),
- IssueDocTesting.newDoc("ISSUE3", module),
- IssueDocTesting.newDoc("ISSUE4", file2),
- IssueDocTesting.newDoc("ISSUE5", subModule),
- IssueDocTesting.newDoc("ISSUE6", file3));
+ IssueDocTesting.newDoc("ISSUE1", project),
+ IssueDocTesting.newDoc("ISSUE2", file1),
+ IssueDocTesting.newDoc("ISSUE3", module),
+ IssueDocTesting.newDoc("ISSUE4", file2),
+ IssueDocTesting.newDoc("ISSUE5", subModule),
+ IssueDocTesting.newDoc("ISSUE6", file3));
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions())
- .getDocs()).hasSize(3);
+ .getDocs()).hasSize(3);
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions())
- .getDocs()).hasSize(1);
+ .getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().moduleRootUuids(newArrayList(subModule.uuid())).build(), new SearchOptions())
- .getDocs()).hasSize(2);
+ .getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder().moduleRootUuids(newArrayList(module.uuid())).build(), new SearchOptions())
- .getDocs()).hasSize(4);
+ .getDocs()).hasSize(4);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new SearchOptions())
- .getDocs()).hasSize(6);
+ .getDocs()).hasSize(6);
assertThat(underTest.search(IssueQuery.builder().viewUuids(newArrayList(view)).build(), new SearchOptions())
- .getDocs()).hasSize(6);
+ .getDocs()).hasSize(6);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new SearchOptions())
- .getDocs()).isEmpty();
+ .getDocs()).isEmpty();
}
@Test
indexView(view, newArrayList(project.uuid()));
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", project),
- IssueDocTesting.newDoc("ISSUE2", file1),
- IssueDocTesting.newDoc("ISSUE3", module),
- IssueDocTesting.newDoc("ISSUE4", file2),
- IssueDocTesting.newDoc("ISSUE5", subModule),
- IssueDocTesting.newDoc("ISSUE6", file3));
+ IssueDocTesting.newDoc("ISSUE1", project),
+ IssueDocTesting.newDoc("ISSUE2", file1),
+ IssueDocTesting.newDoc("ISSUE3", module),
+ IssueDocTesting.newDoc("ISSUE4", file2),
+ IssueDocTesting.newDoc("ISSUE5", subModule),
+ IssueDocTesting.newDoc("ISSUE6", file3));
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project.uuid())).build(), new SearchOptions()).getDocs()).hasSize(6);
// !
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid())).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().fileUuids(newArrayList(file1.uuid(), file2.uuid(), file3.uuid())).build(), new SearchOptions()).getDocs())
- .hasSize(3);
+ .hasSize(3);
}
@Test
ComponentDto file3 = newFileDto(project, null, "CDEF");
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", project),
- IssueDocTesting.newDoc("ISSUE2", file1),
- IssueDocTesting.newDoc("ISSUE3", file2),
- IssueDocTesting.newDoc("ISSUE4", file2),
- IssueDocTesting.newDoc("ISSUE5", file3));
+ IssueDocTesting.newDoc("ISSUE1", project),
+ IssueDocTesting.newDoc("ISSUE2", file1),
+ IssueDocTesting.newDoc("ISSUE3", file2),
+ IssueDocTesting.newDoc("ISSUE4", file2),
+ IssueDocTesting.newDoc("ISSUE5", file3));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("fileUuids")));
assertThat(result.getFacets().getNames()).containsOnly("fileUuids");
assertThat(result.getFacets().get("fileUuids"))
- .containsOnly(entry("A", 1L), entry("ABCD", 1L), entry("BCDE", 2L), entry("CDEF", 1L));
+ .containsOnly(entry("A", 1L), entry("ABCD", 1L), entry("BCDE", 2L), entry("CDEF", 1L));
}
@Test
ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"),
- IssueDocTesting.newDoc("ISSUE2", file2).setDirectoryPath("/"));
+ IssueDocTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"),
+ IssueDocTesting.newDoc("ISSUE2", file2).setDirectoryPath("/"));
assertThat(underTest.search(IssueQuery.builder().directories(newArrayList("/src/main/xoo")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().directories(newArrayList("/")).build(), new SearchOptions()).getDocs()).hasSize(1);
ComponentDto file2 = newFileDto(project, null).setPath("F2.xoo");
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"),
- IssueDocTesting.newDoc("ISSUE2", file2).setDirectoryPath("/"));
+ IssueDocTesting.newDoc("ISSUE1", file1).setDirectoryPath("/src/main/xoo"),
+ IssueDocTesting.newDoc("ISSUE2", file2).setDirectoryPath("/"));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("directories")));
assertThat(result.getFacets().getNames()).containsOnly("directories");
ComponentDto file1 = newFileDto(project1, null);
ComponentDto project2 = newProjectDto(organizationDto);
indexIssues(
- // Project1 has 2 issues (one on a file and one on the project itself)
- IssueDocTesting.newDoc("ISSUE1", project1),
- IssueDocTesting.newDoc("ISSUE2", file1),
- // Project2 has 1 issue
- IssueDocTesting.newDoc("ISSUE3", project2));
+ // Project1 has 2 issues (one on a file and one on the project itself)
+ IssueDocTesting.newDoc("ISSUE1", project1),
+ IssueDocTesting.newDoc("ISSUE2", file1),
+ // Project2 has 1 issue
+ IssueDocTesting.newDoc("ISSUE3", project2));
// The view1 is containing 2 issues from project1
String view1 = "ABCD";
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO),
- IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.MAJOR));
+ IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO),
+ IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.MAJOR));
assertThat(underTest.search(IssueQuery.builder().severities(newArrayList(Severity.INFO, Severity.MAJOR)).build(), new SearchOptions()).getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder().severities(newArrayList(Severity.INFO)).build(), new SearchOptions()).getDocs()).hasSize(1);
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO),
- IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO),
- IssueDocTesting.newDoc("ISSUE3", file).setSeverity(Severity.MAJOR));
+ IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.INFO),
+ IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO),
+ IssueDocTesting.newDoc("ISSUE3", file).setSeverity(Severity.MAJOR));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("severities")));
assertThat(result.getFacets().getNames()).containsOnly("severities");
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED),
- IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN));
+ IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED),
+ IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN));
assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CLOSED, Issue.STATUS_OPEN)).build(), new SearchOptions()).getDocs())
- .hasSize(2);
+ .hasSize(2);
assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CLOSED)).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().statuses(newArrayList(Issue.STATUS_CONFIRMED)).build(), new SearchOptions()).getDocs()).isEmpty();
}
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED),
- IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_CLOSED),
- IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN));
+ IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED),
+ IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_CLOSED),
+ IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("statuses")));
assertThat(result.getFacets().getNames()).containsOnly("statuses");
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
- IssueDocTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FIXED));
+ IssueDocTesting.newDoc("ISSUE1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
+ IssueDocTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FIXED));
assertThat(
- underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)).build(), new SearchOptions())
- .getDocs())
- .hasSize(2);
+ underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE, Issue.RESOLUTION_FIXED)).build(), new SearchOptions())
+ .getDocs())
+ .hasSize(2);
assertThat(underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_FALSE_POSITIVE)).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().resolutions(newArrayList(Issue.RESOLUTION_REMOVED)).build(), new SearchOptions()).getDocs()).isEmpty();
}
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
- IssueDocTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
- IssueDocTesting.newDoc("ISSUE3", file).setResolution(Issue.RESOLUTION_FIXED));
+ IssueDocTesting.newDoc("ISSUE1", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
+ IssueDocTesting.newDoc("ISSUE2", file).setResolution(Issue.RESOLUTION_FALSE_POSITIVE),
+ IssueDocTesting.newDoc("ISSUE3", file).setResolution(Issue.RESOLUTION_FIXED));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("resolutions")));
assertThat(result.getFacets().getNames()).containsOnly("resolutions");
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED),
- IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN).setResolution(null),
- IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN).setResolution(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED),
+ IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_OPEN).setResolution(null),
+ IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_OPEN).setResolution(null));
assertThat(underTest.search(IssueQuery.builder().resolved(true).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().resolved(false).build(), new SearchOptions()).getDocs()).hasSize(2);
indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setRuleKey(ruleKey.toString()).setLanguage("xoo"));
assertThat(underTest.search(IssueQuery.builder().languages(newArrayList("xoo")).build(),
- new SearchOptions()).getDocs()).hasSize(1);
+ new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().languages(newArrayList("unknown")).build(), new SearchOptions()).getDocs()).isEmpty();
}
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
- IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
+ IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
assertThat(underTest.search(IssueQuery.builder().assignees(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().assignees(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2);
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
- IssueDocTesting.newDoc("ISSUE3", file).setAssignee("simon"),
- IssueDocTesting.newDoc("ISSUE4", file).setAssignee(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
+ IssueDocTesting.newDoc("ISSUE3", file).setAssignee("simon"),
+ IssueDocTesting.newDoc("ISSUE4", file).setAssignee(null));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("assignees")));
assertThat(result.getFacets().getNames()).containsOnly("assignees");
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAssignee("j-b"),
- IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
- IssueDocTesting.newDoc("ISSUE3", file).setAssignee("simon"),
- IssueDocTesting.newDoc("ISSUE4", file).setAssignee(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAssignee("j-b"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"),
+ IssueDocTesting.newDoc("ISSUE3", file).setAssignee("simon"),
+ IssueDocTesting.newDoc("ISSUE4", file).setAssignee(null));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().assignees(Arrays.asList("j-b")).build(),
- new SearchOptions().addFacets(newArrayList("assignees")));
+ new SearchOptions().addFacets(newArrayList("assignees")));
assertThat(result.getFacets().getNames()).containsOnly("assignees");
assertThat(result.getFacets().get("assignees")).containsOnly(entry("j-b", 1L), entry("simon", 2L), entry("", 1L));
}
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAssignee(null),
- IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAssignee(null),
+ IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
assertThat(underTest.search(IssueQuery.builder().assigned(true).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().assigned(false).build(), new SearchOptions()).getDocs()).hasSize(2);
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAuthorLogin("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"),
- IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAuthorLogin("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"),
+ IssueDocTesting.newDoc("ISSUE3", file).setAssignee(null));
assertThat(underTest.search(IssueQuery.builder().authors(newArrayList("steph")).build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().authors(newArrayList("steph", "simon")).build(), new SearchOptions()).getDocs()).hasSize(2);
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAuthorLogin("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"),
- IssueDocTesting.newDoc("ISSUE3", file).setAuthorLogin("simon"),
- IssueDocTesting.newDoc("ISSUE4", file).setAuthorLogin(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setAuthorLogin("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAuthorLogin("simon"),
+ IssueDocTesting.newDoc("ISSUE3", file).setAuthorLogin("simon"),
+ IssueDocTesting.newDoc("ISSUE4", file).setAuthorLogin(null));
SearchResult<IssueDoc> result = underTest.search(IssueQuery.builder().build(), new SearchOptions().addFacets(newArrayList("authors")));
assertThat(result.getFacets().getNames()).containsOnly("authors");
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
assertThat(underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).hasSize(2);
// Lower bound is included
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
assertThat(underTest.search(IssueQuery.builder().createdBefore(parseDate("2014-09-19")).build(), new SearchOptions()).getDocs()).isEmpty();
// Upper bound is excluded
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDate("2014-09-23")));
// 19 < createdAt < 25
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-25"))
- .build(), new SearchOptions()).getDocs()).hasSize(2);
+ .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-25"))
+ .build(), new SearchOptions()).getDocs()).hasSize(2);
// 20 < createdAt < 25: excludes first issue
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-25"))
- .build(), new SearchOptions()).getDocs()).hasSize(2);
+ .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-25"))
+ .build(), new SearchOptions()).getDocs()).hasSize(2);
// 21 < createdAt < 25
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-25"))
- .build(), new SearchOptions()).getDocs()).hasSize(1);
+ .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-25"))
+ .build(), new SearchOptions()).getDocs()).hasSize(1);
// 21 < createdAt < 24
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-24"))
- .build(), new SearchOptions()).getDocs()).hasSize(1);
+ .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-24"))
+ .build(), new SearchOptions()).getDocs()).hasSize(1);
// 21 < createdAt < 23: excludes second issue
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-23"))
- .build(), new SearchOptions()).getDocs()).isEmpty();
+ .createdAfter(parseDate("2014-09-21")).createdBefore(parseDate("2014-09-23"))
+ .build(), new SearchOptions()).getDocs()).isEmpty();
// 19 < createdAt < 21: only first issue
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-21"))
- .build(), new SearchOptions()).getDocs()).hasSize(1);
+ .createdAfter(parseDate("2014-09-19")).createdBefore(parseDate("2014-09-21"))
+ .build(), new SearchOptions()).getDocs()).hasSize(1);
// 20 < createdAt < 20: exception
expectedException.expect(IllegalArgumentException.class);
underTest.search(IssueQuery.builder()
- .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-20"))
- .build(), new SearchOptions()).getDocs();
+ .createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-20"))
+ .build(), new SearchOptions()).getDocs();
}
@Test
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-20T00:00:00+0100")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-19T23:00:00+0000")).createdBefore(parseDateTime("2014-09-22T23:00:01+0000"))
- .build(), new SearchOptions()).getDocs()).hasSize(2);
+ .createdAfter(parseDateTime("2014-09-19T23:00:00+0000")).createdBefore(parseDateTime("2014-09-22T23:00:01+0000"))
+ .build(), new SearchOptions()).getDocs()).hasSize(2);
assertThat(underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-19T23:00:01+0000")).createdBefore(parseDateTime("2014-09-22T23:00:00+0000"))
- .build(), new SearchOptions()).getDocs()).hasSize(0);
+ .createdAfter(parseDateTime("2014-09-19T23:00:01+0000")).createdBefore(parseDateTime("2014-09-22T23:00:00+0000"))
+ .build(), new SearchOptions()).getDocs()).hasSize(0);
}
@Test
public void filter_by_created_before_must_be_lower_than_after() {
try {
underTest.search(IssueQuery.builder().createdAfter(parseDate("2014-09-20")).createdBefore(parseDate("2014-09-19")).build(),
- new SearchOptions());
+ new SearchOptions());
Fail.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
} catch (IllegalArgumentException exception) {
assertThat(exception.getMessage()).isEqualTo("Start bound cannot be larger or equal to end bound");
SearchOptions options = fixtureForCreatedAtFacet();
IssueQuery query = IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
- .createdBefore(parseDateTime("2014-09-08T00:00:00+0100"))
- .checkAuthorization(false)
- .build();
+ .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
+ .createdBefore(parseDateTime("2014-09-08T00:00:00+0100"))
+ .checkAuthorization(false)
+ .build();
SearchResult<IssueDoc> result = underTest.search(query, options);
Map<String, Long> buckets = result.getFacets().get("createdAt");
assertThat(buckets).containsOnly(
- entry("2014-08-31T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 2L),
- entry("2014-09-02T01:00:00+0000", 1L),
- entry("2014-09-03T01:00:00+0000", 0L),
- entry("2014-09-04T01:00:00+0000", 0L),
- entry("2014-09-05T01:00:00+0000", 1L),
- entry("2014-09-06T01:00:00+0000", 0L),
- entry("2014-09-07T01:00:00+0000", 0L));
+ entry("2014-08-31T01:00:00+0000", 0L),
+ entry("2014-09-01T01:00:00+0000", 2L),
+ entry("2014-09-02T01:00:00+0000", 1L),
+ entry("2014-09-03T01:00:00+0000", 0L),
+ entry("2014-09-04T01:00:00+0000", 0L),
+ entry("2014-09-05T01:00:00+0000", 1L),
+ entry("2014-09-06T01:00:00+0000", 0L),
+ entry("2014-09-07T01:00:00+0000", 0L));
}
@Test
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
- .createdBefore(parseDateTime("2014-09-21T00:00:00+0100")).build(),
- SearchOptions).getFacets().get("createdAt");
+ .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
+ .createdBefore(parseDateTime("2014-09-21T00:00:00+0100")).build(),
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-25T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 4L),
- entry("2014-09-08T01:00:00+0000", 0L),
- entry("2014-09-15T01:00:00+0000", 1L));
+ entry("2014-08-25T01:00:00+0000", 0L),
+ entry("2014-09-01T01:00:00+0000", 4L),
+ entry("2014-09-08T01:00:00+0000", 0L),
+ entry("2014-09-15T01:00:00+0000", 1L));
}
@Test
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
- .createdBefore(parseDateTime("2015-01-19T00:00:00+0100")).build(),
- SearchOptions).getFacets().get("createdAt");
+ .createdAfter(parseDateTime("2014-09-01T00:00:00+0100"))
+ .createdBefore(parseDateTime("2015-01-19T00:00:00+0100")).build(),
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-08-01T01:00:00+0000", 0L),
- entry("2014-09-01T01:00:00+0000", 5L),
- entry("2014-10-01T01:00:00+0000", 0L),
- entry("2014-11-01T01:00:00+0000", 0L),
- entry("2014-12-01T01:00:00+0000", 0L),
- entry("2015-01-01T01:00:00+0000", 1L));
+ entry("2014-08-01T01:00:00+0000", 0L),
+ entry("2014-09-01T01:00:00+0000", 5L),
+ entry("2014-10-01T01:00:00+0000", 0L),
+ entry("2014-11-01T01:00:00+0000", 0L),
+ entry("2014-12-01T01:00:00+0000", 0L),
+ entry("2015-01-01T01:00:00+0000", 1L));
}
@Test
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2011-01-01T00:00:00+0100"))
- .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
- SearchOptions).getFacets().get("createdAt");
+ .createdAfter(parseDateTime("2011-01-01T00:00:00+0100"))
+ .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2010-01-01T01:00:00+0000", 0L),
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L));
+ entry("2010-01-01T01:00:00+0000", 0L),
+ entry("2011-01-01T01:00:00+0000", 1L),
+ entry("2012-01-01T01:00:00+0000", 0L),
+ entry("2013-01-01T01:00:00+0000", 0L),
+ entry("2014-01-01T01:00:00+0000", 5L),
+ entry("2015-01-01T01:00:00+0000", 1L));
}
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2014-09-01T00:00:00-0100"))
- .createdBefore(parseDateTime("2014-09-02T00:00:00-0100")).build(),
- SearchOptions).getFacets().get("createdAt");
+ .createdAfter(parseDateTime("2014-09-01T00:00:00-0100"))
+ .createdBefore(parseDateTime("2014-09-02T00:00:00-0100")).build(),
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2014-09-01T01:00:00+0000", 2L));
+ entry("2014-09-01T01:00:00+0000", 2L));
}
@Test
SearchOptions options = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdAfter(parseDateTime("2009-01-01T00:00:00+0100"))
- .createdBefore(parseDateTime("2016-01-01T00:00:00+0100"))
- .build(), options).getFacets().get("createdAt");
+ .createdAfter(parseDateTime("2009-01-01T00:00:00+0100"))
+ .createdBefore(parseDateTime("2016-01-01T00:00:00+0100"))
+ .build(), options).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2008-01-01T01:00:00+0000", 0L),
- entry("2009-01-01T01:00:00+0000", 0L),
- entry("2010-01-01T01:00:00+0000", 0L),
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L));
+ entry("2008-01-01T01:00:00+0000", 0L),
+ entry("2009-01-01T01:00:00+0000", 0L),
+ entry("2010-01-01T01:00:00+0000", 0L),
+ entry("2011-01-01T01:00:00+0000", 1L),
+ entry("2012-01-01T01:00:00+0000", 0L),
+ entry("2013-01-01T01:00:00+0000", 0L),
+ entry("2014-01-01T01:00:00+0000", 5L),
+ entry("2015-01-01T01:00:00+0000", 1L));
}
@Test
SearchOptions SearchOptions = fixtureForCreatedAtFacet();
Map<String, Long> createdAt = underTest.search(IssueQuery.builder()
- .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
- SearchOptions).getFacets().get("createdAt");
+ .createdBefore(parseDateTime("2016-01-01T00:00:00+0100")).build(),
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).containsOnly(
- entry("2011-01-01T01:00:00+0000", 1L),
- entry("2012-01-01T01:00:00+0000", 0L),
- entry("2013-01-01T01:00:00+0000", 0L),
- entry("2014-01-01T01:00:00+0000", 5L),
- entry("2015-01-01T01:00:00+0000", 1L));
+ entry("2011-01-01T01:00:00+0000", 1L),
+ entry("2012-01-01T01:00:00+0000", 0L),
+ entry("2013-01-01T01:00:00+0000", 0L),
+ entry("2014-01-01T01:00:00+0000", 5L),
+ entry("2015-01-01T01:00:00+0000", 1L));
}
@Test
SearchOptions SearchOptions = new SearchOptions().addFacets("createdAt");
Map<String, Long> createdAt = underTest.search(IssueQuery.builder().build(),
- SearchOptions).getFacets().get("createdAt");
+ SearchOptions).getFacets().get("createdAt");
assertThat(createdAt).isNull();
}
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_OPEN),
- IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_CLOSED),
- IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_REOPENED));
+ IssueDocTesting.newDoc("ISSUE1", file).setStatus(Issue.STATUS_OPEN),
+ IssueDocTesting.newDoc("ISSUE2", file).setStatus(Issue.STATUS_CLOSED),
+ IssueDocTesting.newDoc("ISSUE3", file).setStatus(Issue.STATUS_REOPENED));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_STATUS).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.BLOCKER),
- IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO),
- IssueDocTesting.newDoc("ISSUE3", file).setSeverity(Severity.MINOR),
- IssueDocTesting.newDoc("ISSUE4", file).setSeverity(Severity.CRITICAL),
- IssueDocTesting.newDoc("ISSUE5", file).setSeverity(Severity.MAJOR));
+ IssueDocTesting.newDoc("ISSUE1", file).setSeverity(Severity.BLOCKER),
+ IssueDocTesting.newDoc("ISSUE2", file).setSeverity(Severity.INFO),
+ IssueDocTesting.newDoc("ISSUE3", file).setSeverity(Severity.MINOR),
+ IssueDocTesting.newDoc("ISSUE4", file).setSeverity(Severity.CRITICAL),
+ IssueDocTesting.newDoc("ISSUE5", file).setSeverity(Severity.MAJOR));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_SEVERITY).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
- IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"));
+ IssueDocTesting.newDoc("ISSUE1", file).setAssignee("steph"),
+ IssueDocTesting.newDoc("ISSUE2", file).setAssignee("simon"));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_ASSIGNEE).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CREATION_DATE).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncUpdateDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncUpdateDate(parseDateTime("2014-09-24T00:00:00+0100")));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncUpdateDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncUpdateDate(parseDateTime("2014-09-24T00:00:00+0100")));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_UPDATE_DATE).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file = newFileDto(project, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE1", file).setFuncCloseDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("ISSUE2", file).setFuncCloseDate(parseDateTime("2014-09-24T00:00:00+0100")),
- IssueDocTesting.newDoc("ISSUE3", file).setFuncCloseDate(null));
+ IssueDocTesting.newDoc("ISSUE1", file).setFuncCloseDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("ISSUE2", file).setFuncCloseDate(parseDateTime("2014-09-24T00:00:00+0100")),
+ IssueDocTesting.newDoc("ISSUE3", file).setFuncCloseDate(null));
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_CLOSE_DATE).asc(true);
SearchResult<IssueDoc> result = underTest.search(query.build(), new SearchOptions());
ComponentDto file2 = newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo");
indexIssues(
- // file F1
- IssueDocTesting.newDoc("F1_2", file1).setLine(20),
- IssueDocTesting.newDoc("F1_1", file1).setLine(null),
- IssueDocTesting.newDoc("F1_3", file1).setLine(25),
+ // file F1
+ IssueDocTesting.newDoc("F1_2", file1).setLine(20),
+ IssueDocTesting.newDoc("F1_1", file1).setLine(null),
+ IssueDocTesting.newDoc("F1_3", file1).setLine(25),
- // file F2
- IssueDocTesting.newDoc("F2_1", file2).setLine(9),
- IssueDocTesting.newDoc("F2_2", file2).setLine(109),
- // two issues on the same line -> sort by key
- IssueDocTesting.newDoc("F2_3", file2).setLine(109));
+ // file F2
+ IssueDocTesting.newDoc("F2_1", file2).setLine(9),
+ IssueDocTesting.newDoc("F2_2", file2).setLine(109),
+ // two issues on the same line -> sort by key
+ IssueDocTesting.newDoc("F2_3", file2).setLine(109));
// ascending sort -> F1 then F2. Line "0" first.
IssueQuery.Builder query = IssueQuery.builder().sort(IssueQuery.SORT_BY_FILE_LINE).asc(true);
ComponentDto file3 = newFileDto(project2, null, "F3").setPath("src/main/xoo/org/sonar/samples/File3.xoo");
indexIssues(
- // file F1 from project P1
- IssueDocTesting.newDoc("F1_1", file1).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("F1_2", file1).setLine(null).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("F1_3", file1).setLine(25).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ // file F1 from project P1
+ IssueDocTesting.newDoc("F1_1", file1).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("F1_2", file1).setLine(null).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("F1_3", file1).setLine(25).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- // file F2 from project P1
- IssueDocTesting.newDoc("F2_1", file2).setLine(9).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- IssueDocTesting.newDoc("F2_2", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- // two issues on the same line -> sort by key
- IssueDocTesting.newDoc("F2_3", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ // file F2 from project P1
+ IssueDocTesting.newDoc("F2_1", file2).setLine(9).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ IssueDocTesting.newDoc("F2_2", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
+ // two issues on the same line -> sort by key
+ IssueDocTesting.newDoc("F2_3", file2).setLine(109).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")),
- // file F3 from project P2
- IssueDocTesting.newDoc("F3_1", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")),
- IssueDocTesting.newDoc("F3_2", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
+ // file F3 from project P2
+ IssueDocTesting.newDoc("F3_1", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-24T00:00:00+0100")),
+ IssueDocTesting.newDoc("F3_2", file3).setLine(20).setFuncCreationDate(parseDateTime("2014-09-23T00:00:00+0100")));
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).extracting(IssueDoc::key)
- .containsExactly("F3_1", "F1_2", "F1_1", "F1_3", "F2_1", "F2_2", "F2_3", "F3_2");
+ .containsExactly("F3_1", "F1_2", "F1_1", "F1_3", "F2_1", "F2_2", "F2_3", "F3_2");
}
@Test
// project3 can be seen by nobody
indexIssue(IssueDocTesting.newDoc("ISSUE3", file3));
- userSessionRule.login().setGroups(group1);
+ userSessionRule.logIn().setGroups(group1);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
- userSessionRule.login().setGroups(group2);
+ userSessionRule.logIn().setGroups(group2);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
- userSessionRule.login().setGroups(group1, group2);
+ userSessionRule.logIn().setGroups(group1, group2);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(2);
GroupDto otherGroup = newGroupDto();
- userSessionRule.login().setGroups(otherGroup);
+ userSessionRule.logIn().setGroups(otherGroup);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).isEmpty();
- userSessionRule.login().setGroups(group1, group2);
+ userSessionRule.logIn().setGroups(group1, group2);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project3.uuid())).build(), new SearchOptions()).getDocs()).isEmpty();
}
authorizationIndexerTester.allowOnlyUser(project2, user2);
indexIssue(IssueDocTesting.newDoc("ISSUE3", file3));
- userSessionRule.login(user1);
+ userSessionRule.logIn(user1);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
assertThat(underTest.search(IssueQuery.builder().projectUuids(newArrayList(project3.key())).build(), new SearchOptions()).getDocs()).hasSize(0);
- userSessionRule.login(user2);
+ userSessionRule.logIn(user2);
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(1);
// another user
- userSessionRule.login(newUserDto());
+ userSessionRule.logIn(newUserDto());
assertThat(underTest.search(IssueQuery.builder().build(), new SearchOptions()).getDocs()).hasSize(0);
}
ComponentDto file = newFileDto(project, null).setPath("src/File.xoo");
IssueDoc issue = IssueDocTesting.newDoc("ISSUE", file)
- .setRuleKey("squid:S001")
- .setChecksum("12345")
- .setAssignee("john")
- .setLine(11)
- .setMessage("the message")
- .setSeverity(Severity.BLOCKER)
- .setManualSeverity(true)
- .setStatus(Issue.STATUS_RESOLVED)
- .setResolution(Issue.RESOLUTION_FIXED)
- .setFuncCreationDate(new Date());
+ .setRuleKey("squid:S001")
+ .setChecksum("12345")
+ .setAssignee("john")
+ .setLine(11)
+ .setMessage("the message")
+ .setSeverity(Severity.BLOCKER)
+ .setManualSeverity(true)
+ .setStatus(Issue.STATUS_RESOLVED)
+ .setResolution(Issue.RESOLUTION_FIXED)
+ .setFuncCreationDate(new Date());
indexIssues(issue);
List<IssueDoc> issues = Lists.newArrayList(underTest.selectIssuesForBatch(file));
ComponentDto file = newFileDto(subModule, null);
indexIssues(
- IssueDocTesting.newDoc("ISSUE3", module),
- IssueDocTesting.newDoc("ISSUE5", subModule),
- IssueDocTesting.newDoc("ISSUE2", file),
- // Close Issue, should never be returned
- IssueDocTesting.newDoc("CLOSE_ISSUE", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED));
+ IssueDocTesting.newDoc("ISSUE3", module),
+ IssueDocTesting.newDoc("ISSUE5", subModule),
+ IssueDocTesting.newDoc("ISSUE2", file),
+ // Close Issue, should never be returned
+ IssueDocTesting.newDoc("CLOSE_ISSUE", file).setStatus(Issue.STATUS_CLOSED).setResolution(Issue.RESOLUTION_FIXED));
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project))).hasSize(3);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(module))).hasSize(3);
// project3 can be seen by nobody
indexIssue(IssueDocTesting.newDoc("ISSUE3", file2));
- userSessionRule.login().setGroups(allowedGroup);
+ userSessionRule.logIn().setGroups(allowedGroup);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project1))).hasSize(1);
- userSessionRule.login().setGroups(otherGroup);
+ userSessionRule.logIn().setGroups(otherGroup);
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(project2))).isEmpty();
}
@Test
public void add_comment() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
call(issueDto.getKey(), "please fix it");
@Test
public void fail_when_missing_issue_key() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call(null, "please fix it");
@Test
public void fail_when_issue_does_not_exist() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(NotFoundException.class);
call("ABCD", "please fix it");
@Test
public void fail_when_missing_comment_text() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call("ABCD", null);
@Test
public void fail_when_empty_comment_text() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
call(issueDto.getKey(), "");
@Test
public void fail_when_not_enough_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), "please fix it");
@Test
public void assign_to_me() throws Exception {
- userSession.login("perceval");
+ userSession.logIn("perceval");
tester.newRequest()
.setParam("issue", "ABC")
@Test
public void assign_to_me_with_deprecated_param() throws Exception {
- userSession.login("perceval");
+ userSession.logIn("perceval");
tester.newRequest()
.setParam("issue", "ABC")
@Test
public void assign_to_someone() throws Exception {
- userSession.login("perceval");
+ userSession.logIn("perceval");
tester.newRequest()
.setParam("issue", "ABC")
@Test
public void unassign() throws Exception {
- userSession.login("perceval");
+ userSession.logIn("perceval");
tester.newRequest()
.setParam("issue", "ABC")
@Test
public void fail_when_number_of_issues_is_more_than_500() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expectMessage("Number of issues is limited to 500");
expectedException.expect(IllegalArgumentException.class);
}
private void setUserProjectPermissions(String... permissions) {
- userSession.login(user);
+ userSession.logIn(user);
addUserProjectPermissions(project, permissions);
}
public void return_changelog() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"));
ChangelogWsResponse result = call(issueDto.getKey());
ComponentDto file1 = db.components().insertComponent(newFileDto(project));
ComponentDto file2 = db.components().insertComponent(newFileDto(project));
IssueDto issueDto = db.issues().insertIssue(newDto(rule, file2, project));
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", file1.uuid(), file2.uuid()));
ChangelogWsResponse result = call(issueDto.getKey());
@Test
public void changelog_of_file_move_is_empty_when_files_does_not_exists() throws Exception {
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setDiff("file", "UNKNOWN_1", "UNKNOWN_2"));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_changelog_on_user_without_email() throws Exception {
UserDto user = db.users().insertUser(UserTesting.newUserDto("john", "John", null));
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"));
ChangelogWsResponse result = call(issueDto.getKey());
@Test
public void return_changelog_not_having_user() throws Exception {
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(null).setDiff("severity", "MAJOR", "BLOCKER"));
ChangelogWsResponse result = call(issueDto.getKey());
@Test
public void return_changelog_on_none_existing_user() throws Exception {
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin("UNKNOWN").setDiff("severity", "MAJOR", "BLOCKER"));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_multiple_diffs() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER").setDiff("status", "RESOLVED", "CLOSED"));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_changelog_when_no_old_value() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", null, "BLOCKER"));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_changelog_when_no_new_value() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", null));
ChangelogWsResponse result = call(issueDto.getKey());
public void return_many_changelog() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto,
new FieldDiffs().setUserLogin(user.getLogin()).setDiff("severity", "MAJOR", "BLOCKER"),
new FieldDiffs().setDiff("status", "RESOLVED", "CLOSED"));
public void replace_technical_debt_key_by_effort() throws Exception {
UserDto user = db.users().insertUser();
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs().setUserLogin(user.getLogin()).setDiff("technicalDebt", "10", "20"));
ChangelogWsResponse result = call(issueDto.getKey());
@Test
public void return_empty_changelog_when_no_changes_on_issue() {
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
ChangelogWsResponse result = call(issueDto.getKey());
@Test
public void fail_when_not_enough_permission() {
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey());
public void test_example() throws Exception {
UserDto user = db.users().insertUser(newUserDto("john.smith", "John Smith", "john@smith.com"));
IssueDto issueDto = db.issues().insertIssue(newIssue());
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
db.issues().insertFieldDiffs(issueDto, new FieldDiffs()
.setUserLogin(user.getLogin())
.setDiff("severity", "MAJOR", "BLOCKER")
public void delete_comment() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
call(commentDto.getKey());
public void delete_comment_using_deprecated_key_parameter() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
public void fail_when_comment_does_not_belong_to_current_user() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only delete your own comments");
public void fail_when_comment_has_not_user() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only delete your own comments");
@Test
public void fail_when_missing_comment_key() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call(null);
@Test
public void fail_when_comment_does_not_exist() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(NotFoundException.class);
call("ABCD");
public void fail_when_not_enough_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(commentDto.getKey());
@Test
public void do_transition() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
call(issueDto.getKey(), "confirm");
@Test
public void fail_if_issue_does_not_exist() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(NotFoundException.class);
call("UNKNOWN", "confirm");
@Test
public void fail_if_no_issue_param() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call(null, "confirm");
@Test
public void fail_if_no_transition_param() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
call(issueDto.getKey(), null);
@Test
public void fail_if_not_enough_permission_to_access_issue() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
- userSession.login("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), "confirm");
@Test
public void fail_if_not_enough_permission_to_apply_transition() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue(newIssue().setStatus(STATUS_OPEN).setResolution(null));
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
// False-positive transition is requiring issue admin permission
expectedException.expect(ForbiddenException.class);
public void edit_comment() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
call(commentDto.getKey(), "please have a look");
public void edit_comment_using_deprecated_key_parameter() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
tester.newRequest().setParam("key", commentDto.getKey()).setParam("text", "please have a look").execute();
public void fail_when_comment_does_not_belong_to_current_user() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("another").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only edit your own comments");
public void fail_when_comment_has_not_user() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, null, "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("You can only edit your own comments");
@Test
public void fail_when_missing_comment_key() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call(null, "please fix it");
@Test
public void fail_when_comment_does_not_exist() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(NotFoundException.class);
call("ABCD", "please fix it");
@Test
public void fail_when_missing_comment_text() throws Exception {
- userSession.login("john");
+ userSession.logIn("john");
expectedException.expect(IllegalArgumentException.class);
call("ABCD", null);
public void fail_when_empty_comment_text() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(IllegalArgumentException.class);
call(commentDto.getKey(), "");
public void fail_when_not_enough_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
IssueChangeDto commentDto = issueDbTester.insertComment(issueDto, "john", "please fix it");
- userSession.login("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(CODEVIEWER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(commentDto.getKey(), "please have a look");
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "directories")
indexView(view.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, view.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.USER, view.uuid());
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, view.uuid())
setAnyoneProjectPermission(view, UserRole.USER);
// User has wrong permission on the view, no issue will be returned
- userSessionRule.login("john").addProjectUuidPermissions(UserRole.CODEVIEWER, view.uuid());
+ userSessionRule.logIn("john").addProjectUuidPermissions(UserRole.CODEVIEWER, view.uuid());
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, view.uuid())
indexView(subView.uuid(), newArrayList(project.uuid()));
setAnyoneProjectPermission(view, UserRole.USER);
- userSessionRule.login("john").addComponentUuidPermission(UserRole.USER, view.uuid(), subView.uuid());
+ userSessionRule.logIn("john").addComponentUuidPermission(UserRole.USER, view.uuid(), subView.uuid());
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid())
setAnyoneProjectPermission(view, UserRole.USER);
// User has wrong permission on the view, no issue will be returned
- userSessionRule.login("john").addComponentUuidPermission(UserRole.CODEVIEWER, view.uuid(), subView.uuid());
+ userSessionRule.logIn("john").addComponentUuidPermission(UserRole.CODEVIEWER, view.uuid(), subView.uuid());
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam(IssuesWsParameters.PARAM_COMPONENT_UUIDS, subView.uuid())
}
private void setAnyoneProjectPermission(ComponentDto project, String permission) {
- userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
// TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
// for each organization
GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, permission, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()));
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("additionalFields", "comments,users")
.execute();
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH).setParam(PARAM_HIDE_COMMENTS, "true").execute();
result.assertJson(this.getClass(), "issue_with_comment_hidden.json");
assertThat(result.outputAsString()).doesNotContain("fabrice");
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,languages,actionPlans,types")
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "statuses,severities,resolutions,projectUuids,rules,fileUuids,assignees,languages,actionPlans")
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam("severities", "MAJOR,MINOR")
@Test
public void assignedToMe_facet_must_escape_login_of_authenticated_user() throws Exception {
// login looks like an invalid regexp
- userSessionRule.login("foo[");
+ userSessionRule.logIn("foo[");
// should not fail
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam("assignees", "__me__")
@Test
public void filter_by_assigned_to_me_unauthenticated() throws Exception {
- userSessionRule.login();
+ userSessionRule.logIn();
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY"));
setDefaultProjectPermission(project);
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john-bob.polop");
+ userSessionRule.logIn("john-bob.polop");
wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam("assignees", "alice")
session.commit();
tester.get(IssueIndexer.class).indexAll();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
WsTester.Result result = wsTester.newGetRequest(CONTROLLER_ISSUES, ACTION_SEARCH)
.setParam("resolved", "false")
.setParam(WebService.Param.FACETS, "severities")
private void setDefaultProjectPermission(ComponentDto project) {
// project can be seen by anyone and by code viewer
- userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
// TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone"
// for each organization
GroupPermissionChange permissionChange = new GroupPermissionChange(PermissionChange.Operation.ADD, UserRole.USER, new ProjectId(project), GroupIdOrAnyone.forAnyone(project.getOrganizationUuid()));
private void setProjectPermission(ComponentDto project, String... permissions) {
// project can be seen by anyone and by code viewer
- userSessionRule.login("admin");
+ userSessionRule.logIn("admin");
Arrays.stream(permissions).forEach(permission -> userSessionRule.addProjectUuidPermissions(permission, project.uuid()));
tester.get(PermissionUpdater.class).apply(session, Arrays.stream(permissions)
// TODO correctly feed default organization. Not a problem as long as issues search does not support "anyone" for each organization
@Test
public void fail_when_missing_browse_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), MAJOR);
@Test
public void fail_when_missing_administer_issue_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), MAJOR);
}
private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
- userSession.login("john")
+ userSession.logIn("john")
.addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
.addProjectUuidPermissions(USER, projectUuid);
}
@Test
public void fail_when_missing_browse_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(ISSUE_ADMIN, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), BUG.name());
@Test
public void fail_when_missing_administer_issue_permission() throws Exception {
IssueDto issueDto = issueDbTester.insertIssue();
- userSession.login("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
+ userSession.logIn("john").addProjectUuidPermissions(USER, issueDto.getProjectUuid());
expectedException.expect(ForbiddenException.class);
call(issueDto.getKey(), BUG.name());
}
private void setUserWithBrowseAndAdministerIssuePermission(String projectUuid) {
- userSession.login("john")
+ userSession.logIn("john")
.addProjectUuidPermissions(ISSUE_ADMIN, projectUuid)
.addProjectUuidPermissions(USER, projectUuid);
}
@Test
public void fail_when_not_system_admin() throws Exception {
- userSession.login("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
+ userSession.logIn("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
definitions.addComponent(PropertyDefinition.builder("foo").build());
expectedException.expect(ForbiddenException.class);
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private void addLicenseSetting(String key, @Nullable String name, String value) {
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))));
- userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.getDbClient().userDao().insert(dbSession, new UserDto()
.setLogin("login")
public void create_text_custom_measure_as_project_admin() throws Exception {
insertProject(DEFAULT_PROJECT_UUID);
MetricDto metric = insertMetric(STRING);
- userSession.login("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
newRequest()
.setParam(CreateAction.PARAM_PROJECT_ID, DEFAULT_PROJECT_UUID)
@Test
public void fail_when_not_enough_permission() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSession.login("login");
+ userSession.logIn("login");
insertProject(DEFAULT_PROJECT_UUID);
MetricDto metric = insertMetric(STRING);
public void delete_in_db_when_admin_on_project() throws Exception {
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid");
dbClient.componentDao().insert(dbSession, project);
- userSessionRule.login("login").addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
+ userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
long id = insertCustomMeasure(newCustomMeasureDto().setComponentUuid("project-uuid"));
newRequest().setParam(PARAM_ID, String.valueOf(id)).execute();
@Test
public void fail_when_insufficient_permissions() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSessionRule.login("login");
+ userSessionRule.logIn("login");
ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), "any-uuid");
dbClient.componentDao().insert(dbSession, project);
long id = insertCustomMeasure(newCustomMeasureDto().setComponentUuid("any-uuid"));
.setEmail("login@login.com")
.setActive(true));
ws = new WsTester(new CustomMeasuresWs(new MetricsAction(dbClient, userSession, new ComponentFinder(dbClient))));
- userSession.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
defaultProject = insertDefaultProject();
}
@Test
public void list_metrics_as_a_project_admin() throws Exception {
insertCustomMetric("metric-key-1");
- userSession.login("login").addProjectUuidPermissions(UserRole.ADMIN, defaultProject.uuid());
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, defaultProject.uuid());
String response = newRequest().outputAsString();
@Test
public void fail_if_insufficient_privilege() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSession.login("login");
+ userSession.logIn("login");
insertCustomMetric("metric-key-1");
CustomMeasureJsonWriter customMeasureJsonWriter = new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule));
ws = new WsTester(new CustomMeasuresWs(new SearchAction(dbClient, customMeasureJsonWriter, userSessionRule, new ComponentFinder(dbClient))));
defaultProject = insertDefaultProject();
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.getDbClient().userDao().insert(dbSession, new UserDto()
.setLogin("login")
@Test
public void search_as_project_admin() throws Exception {
- userSessionRule.login("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
+ userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, DEFAULT_PROJECT_UUID);
MetricDto metric1 = insertCustomMetric(1);
insertCustomMeasure(1, metric1);
@Test
public void fail_when_not_enough_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSessionRule.login("login");
+ userSessionRule.logIn("login");
MetricDto metric1 = insertCustomMetric(1);
insertCustomMeasure(1, metric1);
CustomMeasureValidator validator = new CustomMeasureValidator(newFullTypeValidations());
ws = new WsTester(new CustomMeasuresWs(new UpdateAction(dbClient, userSessionRule, system, validator, new CustomMeasureJsonWriter(new UserJsonWriter(userSessionRule)))));
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.getDbClient().userDao().insert(dbSession, new UserDto()
.setLogin("login")
@Test
public void fail_if_insufficient_privileges() throws Exception {
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name());
dbClient.metricDao().insert(dbSession, metric);
@Test
public void search_paginate_results() {
IntStream.rangeClosed(1, 9)
- .forEach(i -> index(newDoc(newProjectDto(ORG, "P" + i))));
+ .forEach(i -> index(newDoc(newProjectDto(ORG, "P" + i))));
SearchIdResult<String> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().setPage(2, 3));
@Test
public void filter_with_lower_than() {
index(
- newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
- newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
+ newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
+ newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
ProjectMeasuresQuery query = new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 80d));
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 80d));
assertResults(query, PROJECT1);
}
@Test
public void filter_with_lower_than_or_equals() {
index(
- newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
- newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
+ newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
+ newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
ProjectMeasuresQuery query = new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d));
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d));
assertResults(query, PROJECT1, PROJECT2);
}
@Test
public void filter_with_greater_than() {
index(
- newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
- newDoc(PROJECT3, COVERAGE, 80d, NCLOC, 30_001d));
+ newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
+ newDoc(PROJECT3, COVERAGE, 80d, NCLOC, 30_001d));
ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 30_000d));
assertResults(query, PROJECT2, PROJECT3);
@Test
public void filter_with_greater_than_or_equals() {
index(
- newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
- newDoc(PROJECT3, COVERAGE, 80d, NCLOC, 30_001d));
+ newDoc(PROJECT1, COVERAGE, 80d, NCLOC, 30_000d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 30_001d),
+ newDoc(PROJECT3, COVERAGE, 80d, NCLOC, 30_001d));
ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(NCLOC, Operator.GTE, 30_001d));
assertResults(query, PROJECT2, PROJECT3);
@Test
public void filter_with_equals() {
index(
- newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
- newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
+ newDoc(PROJECT1, COVERAGE, 79d, NCLOC, 10_000d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_000d),
+ newDoc(PROJECT3, COVERAGE, 81d, NCLOC, 10_000d));
ProjectMeasuresQuery query = new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.EQ, 80d));
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.EQ, 80d));
assertResults(query, PROJECT2);
}
@Test
public void filter_on_several_metrics() {
index(
- newDoc(PROJECT1, COVERAGE, 81d, NCLOC, 10_001d),
- newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_001d),
- newDoc(PROJECT3, COVERAGE, 79d, NCLOC, 10_000d));
+ newDoc(PROJECT1, COVERAGE, 81d, NCLOC, 10_001d),
+ newDoc(PROJECT2, COVERAGE, 80d, NCLOC, 10_001d),
+ newDoc(PROJECT3, COVERAGE, 79d, NCLOC, 10_000d));
ProjectMeasuresQuery esQuery = new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d))
- .addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 10_000d))
- .addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 11_000d));
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LTE, 80d))
+ .addMetricCriterion(new MetricCriterion(NCLOC, Operator.GT, 10_000d))
+ .addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 11_000d));
assertResults(esQuery, PROJECT2);
}
@Test
public void filter_on_quality_gate_status() {
index(
- newDoc(PROJECT1).setQualityGate("OK"),
- newDoc(PROJECT2).setQualityGate("OK"),
- newDoc(PROJECT3).setQualityGate("WARN"));
+ newDoc(PROJECT1).setQualityGate("OK"),
+ newDoc(PROJECT2).setQualityGate("OK"),
+ newDoc(PROJECT3).setQualityGate("WARN"));
ProjectMeasuresQuery query = new ProjectMeasuresQuery().setQualityGateStatus(OK);
assertResults(query, PROJECT1, PROJECT2);
@Test
public void filter_on_ids() {
index(
- newDoc(PROJECT1),
- newDoc(PROJECT2),
- newDoc(PROJECT3));
+ newDoc(PROJECT1),
+ newDoc(PROJECT2),
+ newDoc(PROJECT3));
ProjectMeasuresQuery query = new ProjectMeasuresQuery().setProjectUuids(newHashSet(PROJECT1.uuid(), PROJECT3.uuid()));
assertResults(query, PROJECT1, PROJECT3);
indexForUser(USER1, newDoc(PROJECT1), newDoc(PROJECT2));
indexForUser(USER2, newDoc(PROJECT3));
- userSession.login(USER1);
+ userSession.logIn(USER1);
assertResults(new ProjectMeasuresQuery(), PROJECT1, PROJECT2);
}
indexForGroup(GROUP1, newDoc(PROJECT1), newDoc(PROJECT2));
indexForGroup(GROUP2, newDoc(PROJECT3));
- userSession.login().setGroups(GROUP1);
+ userSession.logIn().setGroups(GROUP1);
assertResults(new ProjectMeasuresQuery(), PROJECT1, PROJECT2);
}
indexForUser(USER1, newDoc(PROJECT1), newDoc(PROJECT2));
indexForGroup(GROUP1, newDoc(PROJECT3));
- userSession.login(USER1).setGroups(GROUP1);
+ userSession.logIn(USER1).setGroups(GROUP1);
assertResults(new ProjectMeasuresQuery(), PROJECT1, PROJECT2, PROJECT3);
}
@Test
public void does_not_return_facet_when_no_facets_in_options() throws Exception {
index(
- newDoc(PROJECT1, NCLOC, 10d, COVERAGE_KEY, 30d, MAINTAINABILITY_RATING, 3d)
- .setQualityGate(OK.name()));
+ newDoc(PROJECT1, NCLOC, 10d, COVERAGE_KEY, 30d, MAINTAINABILITY_RATING, 3d)
+ .setQualityGate(OK.name()));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions()).getFacets();
@Test
public void facet_ncloc() {
index(
- // 3 docs with ncloc<1K
- newDoc(NCLOC, 0d),
- newDoc(NCLOC, 0d),
- newDoc(NCLOC, 999d),
- // 2 docs with ncloc>=1K and ncloc<10K
- newDoc(NCLOC, 1_000d),
- newDoc(NCLOC, 9_999d),
- // 4 docs with ncloc>=10K and ncloc<100K
- newDoc(NCLOC, 10_000d),
- newDoc(NCLOC, 10_000d),
- newDoc(NCLOC, 11_000d),
- newDoc(NCLOC, 99_000d),
- // 2 docs with ncloc>=100K and ncloc<500K
- newDoc(NCLOC, 100_000d),
- newDoc(NCLOC, 499_000d),
- // 5 docs with ncloc>= 500K
- newDoc(NCLOC, 500_000d),
- newDoc(NCLOC, 100_000_000d),
- newDoc(NCLOC, 500_000d),
- newDoc(NCLOC, 1_000_000d),
- newDoc(NCLOC, 100_000_000_000d));
+ // 3 docs with ncloc<1K
+ newDoc(NCLOC, 0d),
+ newDoc(NCLOC, 0d),
+ newDoc(NCLOC, 999d),
+ // 2 docs with ncloc>=1K and ncloc<10K
+ newDoc(NCLOC, 1_000d),
+ newDoc(NCLOC, 9_999d),
+ // 4 docs with ncloc>=10K and ncloc<100K
+ newDoc(NCLOC, 10_000d),
+ newDoc(NCLOC, 10_000d),
+ newDoc(NCLOC, 11_000d),
+ newDoc(NCLOC, 99_000d),
+ // 2 docs with ncloc>=100K and ncloc<500K
+ newDoc(NCLOC, 100_000d),
+ newDoc(NCLOC, 499_000d),
+ // 5 docs with ncloc>= 500K
+ newDoc(NCLOC, 500_000d),
+ newDoc(NCLOC, 100_000_000d),
+ newDoc(NCLOC, 500_000d),
+ newDoc(NCLOC, 1_000_000d),
+ newDoc(NCLOC, 100_000_000_000d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NCLOC)).getFacets();
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 3L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 4L),
- entry("100000.0-500000.0", 2L),
- entry("500000.0-*", 5L));
+ entry("*-1000.0", 3L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 4L),
+ entry("100000.0-500000.0", 2L),
+ entry("500000.0-*", 5L));
}
@Test
public void facet_ncloc_is_sticky() {
index(
- // 1 docs with ncloc<1K
- newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d),
- // 2 docs with ncloc>=1K and ncloc<10K
- newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d),
- newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d),
- // 3 docs with ncloc>=10K and ncloc<100K
- newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d),
- newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d),
- newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d),
- // 2 docs with ncloc>=100K and ncloc<500K
- newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d),
- newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 0d),
- // 1 docs with ncloc>= 500K
- newDoc(NCLOC, 501_000d, COVERAGE, 81d, DUPLICATION, 20d));
+ // 1 docs with ncloc<1K
+ newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d),
+ // 2 docs with ncloc>=1K and ncloc<10K
+ newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d),
+ newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d),
+ // 3 docs with ncloc>=10K and ncloc<100K
+ newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d),
+ newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d),
+ newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d),
+ // 2 docs with ncloc>=100K and ncloc<500K
+ newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d),
+ newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 0d),
+ // 1 docs with ncloc>= 500K
+ newDoc(NCLOC, 501_000d, COVERAGE, 81d, DUPLICATION, 20d));
Facets facets = underTest.search(new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 10_000d))
- .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)),
- new SearchOptions().addFacets(NCLOC, COVERAGE)).getFacets();
+ .addMetricCriterion(new MetricCriterion(NCLOC, Operator.LT, 10_000d))
+ .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)),
+ new SearchOptions().addFacets(NCLOC, COVERAGE)).getFacets();
// Sticky facet on ncloc does not take into account ncloc filter
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 1L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 3L),
- entry("100000.0-500000.0", 2L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 1L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 3L),
+ entry("100000.0-500000.0", 2L),
+ entry("500000.0-*", 0L));
// But facet on coverage does well take into into filters
assertThat(facets.get(COVERAGE)).containsExactly(
- entry("*-30.0", 3L),
- entry("30.0-50.0", 0L),
- entry("50.0-70.0", 0L),
- entry("70.0-80.0", 0L),
- entry("80.0-*", 0L));
+ entry("*-30.0", 3L),
+ entry("30.0-50.0", 0L),
+ entry("50.0-70.0", 0L),
+ entry("70.0-80.0", 0L),
+ entry("80.0-*", 0L));
}
@Test
public void facet_ncloc_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1,
- // docs with ncloc<1K
- newDoc(NCLOC, 0d),
- newDoc(NCLOC, 100d),
- newDoc(NCLOC, 999d),
- // docs with ncloc>=1K and ncloc<10K
- newDoc(NCLOC, 1_000d),
- newDoc(NCLOC, 9_999d));
+ // docs with ncloc<1K
+ newDoc(NCLOC, 0d),
+ newDoc(NCLOC, 100d),
+ newDoc(NCLOC, 999d),
+ // docs with ncloc>=1K and ncloc<10K
+ newDoc(NCLOC, 1_000d),
+ newDoc(NCLOC, 9_999d));
// User cannot see these projects
indexForUser(USER2,
- // doc with ncloc>=10K and ncloc<100K
- newDoc(NCLOC, 11_000d),
- // doc with ncloc>=100K and ncloc<500K
- newDoc(NCLOC, 499_000d),
- // doc with ncloc>= 500K
- newDoc(NCLOC, 501_000d));
-
- userSession.login(USER1);
+ // doc with ncloc>=10K and ncloc<100K
+ newDoc(NCLOC, 11_000d),
+ // doc with ncloc>=100K and ncloc<500K
+ newDoc(NCLOC, 499_000d),
+ // doc with ncloc>= 500K
+ newDoc(NCLOC, 501_000d));
+
+ userSession.logIn(USER1);
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(NCLOC)).getFacets();
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 3L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 0L),
- entry("100000.0-500000.0", 0L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 3L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 0L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
}
@Test
public void facet_coverage() {
index(
- // 3 docs with coverage<30%
- newDoc(COVERAGE, 0d),
- newDoc(COVERAGE, 0d),
- newDoc(COVERAGE, 29d),
- // 2 docs with coverage>=30% and coverage<50%
- newDoc(COVERAGE, 30d),
- newDoc(COVERAGE, 49d),
- // 4 docs with coverage>=50% and coverage<70%
- newDoc(COVERAGE, 50d),
- newDoc(COVERAGE, 60d),
- newDoc(COVERAGE, 60d),
- newDoc(COVERAGE, 69d),
- // 2 docs with coverage>=70% and coverage<80%
- newDoc(COVERAGE, 70d),
- newDoc(COVERAGE, 79d),
- // 5 docs with coverage>= 80%
- newDoc(COVERAGE, 80d),
- newDoc(COVERAGE, 80d),
- newDoc(COVERAGE, 90d),
- newDoc(COVERAGE, 90.5d),
- newDoc(COVERAGE, 100d));
+ // 3 docs with coverage<30%
+ newDoc(COVERAGE, 0d),
+ newDoc(COVERAGE, 0d),
+ newDoc(COVERAGE, 29d),
+ // 2 docs with coverage>=30% and coverage<50%
+ newDoc(COVERAGE, 30d),
+ newDoc(COVERAGE, 49d),
+ // 4 docs with coverage>=50% and coverage<70%
+ newDoc(COVERAGE, 50d),
+ newDoc(COVERAGE, 60d),
+ newDoc(COVERAGE, 60d),
+ newDoc(COVERAGE, 69d),
+ // 2 docs with coverage>=70% and coverage<80%
+ newDoc(COVERAGE, 70d),
+ newDoc(COVERAGE, 79d),
+ // 5 docs with coverage>= 80%
+ newDoc(COVERAGE, 80d),
+ newDoc(COVERAGE, 80d),
+ newDoc(COVERAGE, 90d),
+ newDoc(COVERAGE, 90.5d),
+ newDoc(COVERAGE, 100d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(COVERAGE)).getFacets();
assertThat(facets.get(COVERAGE)).containsExactly(
- entry("*-30.0", 3L),
- entry("30.0-50.0", 2L),
- entry("50.0-70.0", 4L),
- entry("70.0-80.0", 2L),
- entry("80.0-*", 5L));
+ entry("*-30.0", 3L),
+ entry("30.0-50.0", 2L),
+ entry("50.0-70.0", 4L),
+ entry("70.0-80.0", 2L),
+ entry("80.0-*", 5L));
}
@Test
public void facet_coverage_is_sticky() {
index(
- // docs with coverage<30%
- newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d),
- newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d),
- newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d),
- // docs with coverage>=30% and coverage<50%
- newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d),
- newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d),
- // docs with coverage>=50% and coverage<70%
- newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d),
- // docs with coverage>=70% and coverage<80%
- newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d),
- // docs with coverage>= 80%
- newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 15d),
- newDoc(NCLOC, 501_000d, COVERAGE, 810d, DUPLICATION, 20d));
+ // docs with coverage<30%
+ newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d),
+ newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d),
+ newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d),
+ // docs with coverage>=30% and coverage<50%
+ newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d),
+ newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d),
+ // docs with coverage>=50% and coverage<70%
+ newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d),
+ // docs with coverage>=70% and coverage<80%
+ newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d),
+ // docs with coverage>= 80%
+ newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 15d),
+ newDoc(NCLOC, 501_000d, COVERAGE, 810d, DUPLICATION, 20d));
Facets facets = underTest.search(new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d))
- .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)),
- new SearchOptions().addFacets(COVERAGE, NCLOC)).getFacets();
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d))
+ .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)),
+ new SearchOptions().addFacets(COVERAGE, NCLOC)).getFacets();
// Sticky facet on coverage does not take into account coverage filter
assertThat(facets.get(COVERAGE)).containsExactly(
- entry("*-30.0", 3L),
- entry("30.0-50.0", 2L),
- entry("50.0-70.0", 1L),
- entry("70.0-80.0", 1L),
- entry("80.0-*", 0L));
+ entry("*-30.0", 3L),
+ entry("30.0-50.0", 2L),
+ entry("50.0-70.0", 1L),
+ entry("70.0-80.0", 1L),
+ entry("80.0-*", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 1L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 0L),
- entry("100000.0-500000.0", 0L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 1L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 0L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
}
@Test
public void facet_coverage_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1,
- // docs with coverage<30%
- newDoc(COVERAGE, 0d),
- newDoc(COVERAGE, 0d),
- newDoc(COVERAGE, 29d),
- // docs with coverage>=30% and coverage<50%
- newDoc(COVERAGE, 30d),
- newDoc(COVERAGE, 49d));
+ // docs with coverage<30%
+ newDoc(COVERAGE, 0d),
+ newDoc(COVERAGE, 0d),
+ newDoc(COVERAGE, 29d),
+ // docs with coverage>=30% and coverage<50%
+ newDoc(COVERAGE, 30d),
+ newDoc(COVERAGE, 49d));
// User cannot see these projects
indexForUser(USER2,
- // docs with coverage>=50% and coverage<70%
- newDoc(COVERAGE, 50d),
- // docs with coverage>=70% and coverage<80%
- newDoc(COVERAGE, 70d),
- // docs with coverage>= 80%
- newDoc(COVERAGE, 80d));
-
- userSession.login(USER1);
+ // docs with coverage>=50% and coverage<70%
+ newDoc(COVERAGE, 50d),
+ // docs with coverage>=70% and coverage<80%
+ newDoc(COVERAGE, 70d),
+ // docs with coverage>= 80%
+ newDoc(COVERAGE, 80d));
+
+ userSession.logIn(USER1);
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(COVERAGE)).getFacets();
assertThat(facets.get(COVERAGE)).containsExactly(
- entry("*-30.0", 3L),
- entry("30.0-50.0", 2L),
- entry("50.0-70.0", 0L),
- entry("70.0-80.0", 0L),
- entry("80.0-*", 0L));
+ entry("*-30.0", 3L),
+ entry("30.0-50.0", 2L),
+ entry("50.0-70.0", 0L),
+ entry("70.0-80.0", 0L),
+ entry("80.0-*", 0L));
}
@Test
public void facet_duplicated_lines_density() {
index(
- // 3 docs with duplication<3%
- newDoc(DUPLICATION, 0d),
- newDoc(DUPLICATION, 0d),
- newDoc(DUPLICATION, 2.9d),
- // 2 docs with duplication>=3% and duplication<5%
- newDoc(DUPLICATION, 3d),
- newDoc(DUPLICATION, 4.9d),
- // 4 docs with duplication>=5% and duplication<10%
- newDoc(DUPLICATION, 5d),
- newDoc(DUPLICATION, 6d),
- newDoc(DUPLICATION, 6d),
- newDoc(DUPLICATION, 9.9d),
- // 2 docs with duplication>=10% and duplication<20%
- newDoc(DUPLICATION, 10d),
- newDoc(DUPLICATION, 19.9d),
- // 5 docs with duplication>= 20%
- newDoc(DUPLICATION, 20d),
- newDoc(DUPLICATION, 20d),
- newDoc(DUPLICATION, 50d),
- newDoc(DUPLICATION, 80d),
- newDoc(DUPLICATION, 100d));
+ // 3 docs with duplication<3%
+ newDoc(DUPLICATION, 0d),
+ newDoc(DUPLICATION, 0d),
+ newDoc(DUPLICATION, 2.9d),
+ // 2 docs with duplication>=3% and duplication<5%
+ newDoc(DUPLICATION, 3d),
+ newDoc(DUPLICATION, 4.9d),
+ // 4 docs with duplication>=5% and duplication<10%
+ newDoc(DUPLICATION, 5d),
+ newDoc(DUPLICATION, 6d),
+ newDoc(DUPLICATION, 6d),
+ newDoc(DUPLICATION, 9.9d),
+ // 2 docs with duplication>=10% and duplication<20%
+ newDoc(DUPLICATION, 10d),
+ newDoc(DUPLICATION, 19.9d),
+ // 5 docs with duplication>= 20%
+ newDoc(DUPLICATION, 20d),
+ newDoc(DUPLICATION, 20d),
+ newDoc(DUPLICATION, 50d),
+ newDoc(DUPLICATION, 80d),
+ newDoc(DUPLICATION, 100d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(DUPLICATION)).getFacets();
assertThat(facets.get(DUPLICATION)).containsExactly(
- entry("*-3.0", 3L),
- entry("3.0-5.0", 2L),
- entry("5.0-10.0", 4L),
- entry("10.0-20.0", 2L),
- entry("20.0-*", 5L));
+ entry("*-3.0", 3L),
+ entry("3.0-5.0", 2L),
+ entry("5.0-10.0", 4L),
+ entry("10.0-20.0", 2L),
+ entry("20.0-*", 5L));
}
@Test
public void facet_duplicated_lines_density_is_sticky() {
index(
- // docs with duplication<3%
- newDoc(DUPLICATION, 0d, NCLOC, 999d, COVERAGE, 0d),
- // docs with duplication>=3% and duplication<5%
- newDoc(DUPLICATION, 3d, NCLOC, 5000d, COVERAGE, 0d),
- newDoc(DUPLICATION, 4.9d, NCLOC, 6000d, COVERAGE, 0d),
- // docs with duplication>=5% and duplication<10%
- newDoc(DUPLICATION, 5d, NCLOC, 11000d, COVERAGE, 0d),
- // docs with duplication>=10% and duplication<20%
- newDoc(DUPLICATION, 10d, NCLOC, 120000d, COVERAGE, 10d),
- newDoc(DUPLICATION, 19.9d, NCLOC, 130000d, COVERAGE, 20d),
- // docs with duplication>= 20%
- newDoc(DUPLICATION, 20d, NCLOC, 1000000d, COVERAGE, 40d));
+ // docs with duplication<3%
+ newDoc(DUPLICATION, 0d, NCLOC, 999d, COVERAGE, 0d),
+ // docs with duplication>=3% and duplication<5%
+ newDoc(DUPLICATION, 3d, NCLOC, 5000d, COVERAGE, 0d),
+ newDoc(DUPLICATION, 4.9d, NCLOC, 6000d, COVERAGE, 0d),
+ // docs with duplication>=5% and duplication<10%
+ newDoc(DUPLICATION, 5d, NCLOC, 11000d, COVERAGE, 0d),
+ // docs with duplication>=10% and duplication<20%
+ newDoc(DUPLICATION, 10d, NCLOC, 120000d, COVERAGE, 10d),
+ newDoc(DUPLICATION, 19.9d, NCLOC, 130000d, COVERAGE, 20d),
+ // docs with duplication>= 20%
+ newDoc(DUPLICATION, 20d, NCLOC, 1000000d, COVERAGE, 40d));
Facets facets = underTest.search(new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d))
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)),
- new SearchOptions().addFacets(DUPLICATION, NCLOC)).getFacets();
+ .addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d))
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)),
+ new SearchOptions().addFacets(DUPLICATION, NCLOC)).getFacets();
// Sticky facet on duplication does not take into account duplication filter
assertThat(facets.get(DUPLICATION)).containsExactly(
- entry("*-3.0", 1L),
- entry("3.0-5.0", 2L),
- entry("5.0-10.0", 1L),
- entry("10.0-20.0", 2L),
- entry("20.0-*", 0L));
+ entry("*-3.0", 1L),
+ entry("3.0-5.0", 2L),
+ entry("5.0-10.0", 1L),
+ entry("10.0-20.0", 2L),
+ entry("20.0-*", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 1L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 1L),
- entry("100000.0-500000.0", 0L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 1L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 1L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
}
@Test
public void facet_duplicated_lines_density_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1,
- // docs with duplication<3%
- newDoc(DUPLICATION, 0d),
- newDoc(DUPLICATION, 0d),
- newDoc(DUPLICATION, 2.9d),
- // docs with duplication>=3% and duplication<5%
- newDoc(DUPLICATION, 3d),
- newDoc(DUPLICATION, 4.9d));
+ // docs with duplication<3%
+ newDoc(DUPLICATION, 0d),
+ newDoc(DUPLICATION, 0d),
+ newDoc(DUPLICATION, 2.9d),
+ // docs with duplication>=3% and duplication<5%
+ newDoc(DUPLICATION, 3d),
+ newDoc(DUPLICATION, 4.9d));
// User cannot see these projects
indexForUser(USER2,
- // docs with duplication>=5% and duplication<10%
- newDoc(DUPLICATION, 5d),
- // docs with duplication>=10% and duplication<20%
- newDoc(DUPLICATION, 10d),
- // docs with duplication>= 20%
- newDoc(DUPLICATION, 20d));
-
- userSession.login(USER1);
+ // docs with duplication>=5% and duplication<10%
+ newDoc(DUPLICATION, 5d),
+ // docs with duplication>=10% and duplication<20%
+ newDoc(DUPLICATION, 10d),
+ // docs with duplication>= 20%
+ newDoc(DUPLICATION, 20d));
+
+ userSession.logIn(USER1);
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(DUPLICATION)).getFacets();
assertThat(facets.get(DUPLICATION)).containsExactly(
- entry("*-3.0", 3L),
- entry("3.0-5.0", 2L),
- entry("5.0-10.0", 0L),
- entry("10.0-20.0", 0L),
- entry("20.0-*", 0L));
+ entry("*-3.0", 3L),
+ entry("3.0-5.0", 2L),
+ entry("5.0-10.0", 0L),
+ entry("10.0-20.0", 0L),
+ entry("20.0-*", 0L));
}
@Test
public void facet_maintainability_rating() {
index(
- // 3 docs with rating A
- newDoc(MAINTAINABILITY_RATING, 1d),
- newDoc(MAINTAINABILITY_RATING, 1d),
- newDoc(MAINTAINABILITY_RATING, 1d),
- // 2 docs with rating B
- newDoc(MAINTAINABILITY_RATING, 2d),
- newDoc(MAINTAINABILITY_RATING, 2d),
- // 4 docs with rating C
- newDoc(MAINTAINABILITY_RATING, 3d),
- newDoc(MAINTAINABILITY_RATING, 3d),
- newDoc(MAINTAINABILITY_RATING, 3d),
- newDoc(MAINTAINABILITY_RATING, 3d),
- // 2 docs with rating D
- newDoc(MAINTAINABILITY_RATING, 4d),
- newDoc(MAINTAINABILITY_RATING, 4d),
- // 5 docs with rating E
- newDoc(MAINTAINABILITY_RATING, 5d),
- newDoc(MAINTAINABILITY_RATING, 5d),
- newDoc(MAINTAINABILITY_RATING, 5d),
- newDoc(MAINTAINABILITY_RATING, 5d),
- newDoc(MAINTAINABILITY_RATING, 5d));
+ // 3 docs with rating A
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ // 2 docs with rating B
+ newDoc(MAINTAINABILITY_RATING, 2d),
+ newDoc(MAINTAINABILITY_RATING, 2d),
+ // 4 docs with rating C
+ newDoc(MAINTAINABILITY_RATING, 3d),
+ newDoc(MAINTAINABILITY_RATING, 3d),
+ newDoc(MAINTAINABILITY_RATING, 3d),
+ newDoc(MAINTAINABILITY_RATING, 3d),
+ // 2 docs with rating D
+ newDoc(MAINTAINABILITY_RATING, 4d),
+ newDoc(MAINTAINABILITY_RATING, 4d),
+ // 5 docs with rating E
+ newDoc(MAINTAINABILITY_RATING, 5d),
+ newDoc(MAINTAINABILITY_RATING, 5d),
+ newDoc(MAINTAINABILITY_RATING, 5d),
+ newDoc(MAINTAINABILITY_RATING, 5d),
+ newDoc(MAINTAINABILITY_RATING, 5d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(
- entry("1", 3L),
- entry("2", 2L),
- entry("3", 4L),
- entry("4", 2L),
- entry("5", 5L));
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 2L),
+ entry("5", 5L));
}
@Test
public void facet_maintainability_rating_is_sticky() {
index(
- // docs with rating A
- newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 100d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 200d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 999d, COVERAGE, 0d),
- // docs with rating B
- newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 2000d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 5000d, COVERAGE, 0d),
- // docs with rating C
- newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 20000d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 30000d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 40000d, COVERAGE, 0d),
- newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 50000d, COVERAGE, 0d),
- // docs with rating D
- newDoc(MAINTAINABILITY_RATING, 4d, NCLOC, 120000d, COVERAGE, 0d),
- // docs with rating E
- newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 600000d, COVERAGE, 40d),
- newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 700000d, COVERAGE, 50d),
- newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 800000d, COVERAGE, 60d));
+ // docs with rating A
+ newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 100d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 200d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 1d, NCLOC, 999d, COVERAGE, 0d),
+ // docs with rating B
+ newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 2000d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 2d, NCLOC, 5000d, COVERAGE, 0d),
+ // docs with rating C
+ newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 20000d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 30000d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 40000d, COVERAGE, 0d),
+ newDoc(MAINTAINABILITY_RATING, 3d, NCLOC, 50000d, COVERAGE, 0d),
+ // docs with rating D
+ newDoc(MAINTAINABILITY_RATING, 4d, NCLOC, 120000d, COVERAGE, 0d),
+ // docs with rating E
+ newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 600000d, COVERAGE, 40d),
+ newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 700000d, COVERAGE, 50d),
+ newDoc(MAINTAINABILITY_RATING, 5d, NCLOC, 800000d, COVERAGE, 60d));
Facets facets = underTest.search(new ProjectMeasuresQuery()
- .addMetricCriterion(new MetricCriterion(MAINTAINABILITY_RATING, Operator.LT, 3d))
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)),
- new SearchOptions().addFacets(MAINTAINABILITY_RATING, NCLOC)).getFacets();
+ .addMetricCriterion(new MetricCriterion(MAINTAINABILITY_RATING, Operator.LT, 3d))
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)),
+ new SearchOptions().addFacets(MAINTAINABILITY_RATING, NCLOC)).getFacets();
// Sticky facet on maintainability rating does not take into account maintainability rating filter
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(
- entry("1", 3L),
- entry("2", 2L),
- entry("3", 4L),
- entry("4", 1L),
- entry("5", 0L));
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 1L),
+ entry("5", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 3L),
- entry("1000.0-10000.0", 2L),
- entry("10000.0-100000.0", 0L),
- entry("100000.0-500000.0", 0L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 3L),
+ entry("1000.0-10000.0", 2L),
+ entry("10000.0-100000.0", 0L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
}
@Test
public void facet_maintainability_rating_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1,
- // 3 docs with rating A
- newDoc(MAINTAINABILITY_RATING, 1d),
- newDoc(MAINTAINABILITY_RATING, 1d),
- newDoc(MAINTAINABILITY_RATING, 1d),
- // 2 docs with rating B
- newDoc(MAINTAINABILITY_RATING, 2d),
- newDoc(MAINTAINABILITY_RATING, 2d));
+ // 3 docs with rating A
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ newDoc(MAINTAINABILITY_RATING, 1d),
+ // 2 docs with rating B
+ newDoc(MAINTAINABILITY_RATING, 2d),
+ newDoc(MAINTAINABILITY_RATING, 2d));
// User cannot see these projects
indexForUser(USER2,
- // docs with rating C
- newDoc(MAINTAINABILITY_RATING, 3d),
- // docs with rating D
- newDoc(MAINTAINABILITY_RATING, 4d),
- // docs with rating E
- newDoc(MAINTAINABILITY_RATING, 5d));
-
- userSession.login(USER1);
+ // docs with rating C
+ newDoc(MAINTAINABILITY_RATING, 3d),
+ // docs with rating D
+ newDoc(MAINTAINABILITY_RATING, 4d),
+ // docs with rating E
+ newDoc(MAINTAINABILITY_RATING, 5d));
+
+ userSession.logIn(USER1);
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(MAINTAINABILITY_RATING)).getFacets();
assertThat(facets.get(MAINTAINABILITY_RATING)).containsExactly(
- entry("1", 3L),
- entry("2", 2L),
- entry("3", 0L),
- entry("4", 0L),
- entry("5", 0L));
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 0L),
+ entry("4", 0L),
+ entry("5", 0L));
}
@Test
public void facet_reliability_rating() {
index(
- // 3 docs with rating A
- newDoc(RELIABILITY_RATING, 1d),
- newDoc(RELIABILITY_RATING, 1d),
- newDoc(RELIABILITY_RATING, 1d),
- // 2 docs with rating B
- newDoc(RELIABILITY_RATING, 2d),
- newDoc(RELIABILITY_RATING, 2d),
- // 4 docs with rating C
- newDoc(RELIABILITY_RATING, 3d),
- newDoc(RELIABILITY_RATING, 3d),
- newDoc(RELIABILITY_RATING, 3d),
- newDoc(RELIABILITY_RATING, 3d),
- // 2 docs with rating D
- newDoc(RELIABILITY_RATING, 4d),
- newDoc(RELIABILITY_RATING, 4d),
- // 5 docs with rating E
- newDoc(RELIABILITY_RATING, 5d),
- newDoc(RELIABILITY_RATING, 5d),
- newDoc(RELIABILITY_RATING, 5d),
- newDoc(RELIABILITY_RATING, 5d),
- newDoc(RELIABILITY_RATING, 5d));
+ // 3 docs with rating A
+ newDoc(RELIABILITY_RATING, 1d),
+ newDoc(RELIABILITY_RATING, 1d),
+ newDoc(RELIABILITY_RATING, 1d),
+ // 2 docs with rating B
+ newDoc(RELIABILITY_RATING, 2d),
+ newDoc(RELIABILITY_RATING, 2d),
+ // 4 docs with rating C
+ newDoc(RELIABILITY_RATING, 3d),
+ newDoc(RELIABILITY_RATING, 3d),
+ newDoc(RELIABILITY_RATING, 3d),
+ newDoc(RELIABILITY_RATING, 3d),
+ // 2 docs with rating D
+ newDoc(RELIABILITY_RATING, 4d),
+ newDoc(RELIABILITY_RATING, 4d),
+ // 5 docs with rating E
+ newDoc(RELIABILITY_RATING, 5d),
+ newDoc(RELIABILITY_RATING, 5d),
+ newDoc(RELIABILITY_RATING, 5d),
+ newDoc(RELIABILITY_RATING, 5d),
+ newDoc(RELIABILITY_RATING, 5d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets();
assertThat(facets.get(RELIABILITY_RATING)).containsExactly(
- entry("1", 3L),
- entry("2", 2L),
- entry("3", 4L),
- entry("4", 2L),
- entry("5", 5L));
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 2L),
+ entry("5", 5L));
}
@Test
public void facet_security_rating() {
index(
- // 3 docs with rating A
- newDoc(SECURITY_RATING, 1.0d),
- newDoc(SECURITY_RATING, 1.0d),
- newDoc(SECURITY_RATING, 1.0d),
- // 2 docs with rating B
- newDoc(SECURITY_RATING, 2.0d),
- newDoc(SECURITY_RATING, 2.0d),
- // 4 docs with rating C
- newDoc(SECURITY_RATING, 3.0d),
- newDoc(SECURITY_RATING, 3.0d),
- newDoc(SECURITY_RATING, 3.0d),
- newDoc(SECURITY_RATING, 3.0d),
- // 2 docs with rating D
- newDoc(SECURITY_RATING, 4.0d),
- newDoc(SECURITY_RATING, 4.0d),
- // 5 docs with rating E
- newDoc(SECURITY_RATING, 5.0d),
- newDoc(SECURITY_RATING, 5.0d),
- newDoc(SECURITY_RATING, 5.0d),
- newDoc(SECURITY_RATING, 5.0d),
- newDoc(SECURITY_RATING, 5.0d));
+ // 3 docs with rating A
+ newDoc(SECURITY_RATING, 1.0d),
+ newDoc(SECURITY_RATING, 1.0d),
+ newDoc(SECURITY_RATING, 1.0d),
+ // 2 docs with rating B
+ newDoc(SECURITY_RATING, 2.0d),
+ newDoc(SECURITY_RATING, 2.0d),
+ // 4 docs with rating C
+ newDoc(SECURITY_RATING, 3.0d),
+ newDoc(SECURITY_RATING, 3.0d),
+ newDoc(SECURITY_RATING, 3.0d),
+ newDoc(SECURITY_RATING, 3.0d),
+ // 2 docs with rating D
+ newDoc(SECURITY_RATING, 4.0d),
+ newDoc(SECURITY_RATING, 4.0d),
+ // 5 docs with rating E
+ newDoc(SECURITY_RATING, 5.0d),
+ newDoc(SECURITY_RATING, 5.0d),
+ newDoc(SECURITY_RATING, 5.0d),
+ newDoc(SECURITY_RATING, 5.0d),
+ newDoc(SECURITY_RATING, 5.0d));
Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(SECURITY_RATING)).getFacets();
assertThat(facets.get(SECURITY_RATING)).containsExactly(
- entry("1", 3L),
- entry("2", 2L),
- entry("3", 4L),
- entry("4", 2L),
- entry("5", 5L));
+ entry("1", 3L),
+ entry("2", 2L),
+ entry("3", 4L),
+ entry("4", 2L),
+ entry("5", 5L));
}
@Test
public void facet_quality_gate() {
index(
- // 2 docs with QG OK
- newDoc().setQualityGate(OK.name()),
- newDoc().setQualityGate(OK.name()),
- // 3 docs with QG WARN
- newDoc().setQualityGate(WARN.name()),
- newDoc().setQualityGate(WARN.name()),
- newDoc().setQualityGate(WARN.name()),
- // 4 docs with QG ERROR
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()));
+ // 2 docs with QG OK
+ newDoc().setQualityGate(OK.name()),
+ newDoc().setQualityGate(OK.name()),
+ // 3 docs with QG WARN
+ newDoc().setQualityGate(WARN.name()),
+ newDoc().setQualityGate(WARN.name()),
+ newDoc().setQualityGate(WARN.name()),
+ // 4 docs with QG ERROR
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()));
LinkedHashMap<String, Long> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(ALERT_STATUS_KEY)).getFacets().get(ALERT_STATUS_KEY);
assertThat(result).containsExactly(
- entry(ERROR.name(), 4L),
- entry(WARN.name(), 3L),
- entry(OK.name(), 2L));
+ entry(ERROR.name(), 4L),
+ entry(WARN.name(), 3L),
+ entry(OK.name(), 2L));
}
@Test
public void facet_quality_gate_is_sticky() {
index(
- // 2 docs with QG OK
- newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGate(OK.name()),
- newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGate(OK.name()),
- // 3 docs with QG WARN
- newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
- newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
- newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
- // 4 docs with QG ERROR
- newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(ERROR.name()),
- newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualityGate(ERROR.name()),
- newDoc(NCLOC, 12000d, COVERAGE, 50d).setQualityGate(ERROR.name()),
- newDoc(NCLOC, 13000d, COVERAGE, 60d).setQualityGate(ERROR.name()));
+ // 2 docs with QG OK
+ newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGate(OK.name()),
+ newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGate(OK.name()),
+ // 3 docs with QG WARN
+ newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
+ newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
+ newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(WARN.name()),
+ // 4 docs with QG ERROR
+ newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGate(ERROR.name()),
+ newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualityGate(ERROR.name()),
+ newDoc(NCLOC, 12000d, COVERAGE, 50d).setQualityGate(ERROR.name()),
+ newDoc(NCLOC, 13000d, COVERAGE, 60d).setQualityGate(ERROR.name()));
Facets facets = underTest.search(new ProjectMeasuresQuery()
- .setQualityGateStatus(ERROR)
- .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 55d)),
- new SearchOptions().addFacets(ALERT_STATUS_KEY, NCLOC)).getFacets();
+ .setQualityGateStatus(ERROR)
+ .addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 55d)),
+ new SearchOptions().addFacets(ALERT_STATUS_KEY, NCLOC)).getFacets();
// Sticky facet on quality gate does not take into account quality gate filter
assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(
- entry(OK.name(), 2L),
- entry(WARN.name(), 3L),
- entry(ERROR.name(), 3L));
+ entry(OK.name(), 2L),
+ entry(WARN.name(), 3L),
+ entry(ERROR.name(), 3L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(
- entry("*-1000.0", 1L),
- entry("1000.0-10000.0", 1L),
- entry("10000.0-100000.0", 1L),
- entry("100000.0-500000.0", 0L),
- entry("500000.0-*", 0L));
+ entry("*-1000.0", 1L),
+ entry("1000.0-10000.0", 1L),
+ entry("10000.0-100000.0", 1L),
+ entry("100000.0-500000.0", 0L),
+ entry("500000.0-*", 0L));
}
@Test
public void facet_quality_gate_contains_only_projects_authorized_for_user() throws Exception {
// User can see these projects
indexForUser(USER1,
- // 2 docs with QG OK
- newDoc().setQualityGate(OK.name()),
- newDoc().setQualityGate(OK.name()),
- // 3 docs with QG WARN
- newDoc().setQualityGate(WARN.name()),
- newDoc().setQualityGate(WARN.name()),
- newDoc().setQualityGate(WARN.name()));
+ // 2 docs with QG OK
+ newDoc().setQualityGate(OK.name()),
+ newDoc().setQualityGate(OK.name()),
+ // 3 docs with QG WARN
+ newDoc().setQualityGate(WARN.name()),
+ newDoc().setQualityGate(WARN.name()),
+ newDoc().setQualityGate(WARN.name()));
// User cannot see these projects
indexForUser(USER2,
- // 4 docs with QG ERROR
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()),
- newDoc().setQualityGate(ERROR.name()));
+ // 4 docs with QG ERROR
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()),
+ newDoc().setQualityGate(ERROR.name()));
- userSession.login(USER1);
+ userSession.logIn(USER1);
LinkedHashMap<String, Long> result = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(ALERT_STATUS_KEY)).getFacets().get(ALERT_STATUS_KEY);
assertThat(result).containsExactly(
- entry(ERROR.name(), 0L),
- entry(WARN.name(), 3L),
- entry(OK.name(), 2L));
+ entry(ERROR.name(), 0L),
+ entry(WARN.name(), 3L),
+ entry(OK.name(), 2L));
}
private void index(ProjectMeasuresDoc... docs) {
private static ProjectMeasuresDoc newDoc(ComponentDto project) {
return new ProjectMeasuresDoc()
- .setId(project.uuid())
- .setKey(project.key())
- .setName(project.name());
+ .setId(project.uuid())
+ .setKey(project.key())
+ .setName(project.name());
}
private static ProjectMeasuresDoc newDoc() {
@Before
public void setUp() {
- userSession.login().setRoot().setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn().setRoot().setGlobalPermissions(SYSTEM_ADMIN);
}
@Test
@Test
public void fail_when_not_enough_permission() {
- userSession.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), PROJECT_UUID));
insertNclocMetric();
@Before
public void setUp() {
- userSession.login().setRoot().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().setRoot().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
resourceTypes.setChildrenQualifiers(Qualifiers.MODULE, Qualifiers.FILE, Qualifiers.DIRECTORY);
resourceTypes.setLeavesQualifiers(Qualifiers.FILE, Qualifiers.UNIT_TEST_FILE);
}
@Before
public void setUp() throws Exception {
user = db.users().insertUser("john");
- userSession.login(user);
+ userSession.logIn(user);
}
@Test
@Test
public void fail_if_not_enough_permissions() {
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
expectedException.expect(ForbiddenException.class);
@Before
public void setUp() {
ws = new WsTester(new MetricsWs(new CreateAction(dbClient, userSessionRule)));
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
@Test
@Test
public void fail_when_insufficient_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSessionRule.login("login");
+ userSessionRule.logIn("login");
newRequest()
.setParam(PARAM_KEY, "any-key")
@Before
public void setUp() {
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
ws = new WsTester(new MetricsWs(new DeleteAction(dbClient, userSessionRule)));
metricDao = dbClient.metricDao();
}
@Before
public void setUp() {
ws = new WsTester(new MetricsWs(new UpdateAction(dbClient, userSessionRule)));
- userSessionRule.login("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("login").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
@Test
@Test
public void fail_when_insufficient_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSessionRule.login("login");
+ userSessionRule.logIn("login");
newRequest().execute();
}
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(123);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(123);
@Rule
public DbTester db = DbTester.create();
private DbClient dbClient = db.getDbClient();
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(123);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(123);
@Rule
public DbTester db = DbTester.create();
private DbClient dbClient = db.getDbClient();
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Rule
- public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(123);
+ public UserSessionRule userSession = UserSessionRule.standalone().logIn().setUserId(123);
@Rule
public DbTester db = DbTester.create();
private DbClient dbClient = db.getDbClient();
@Test
public void request_fails_if_user_is_not_root_and_logged_in_user_can_not_create_organizations() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void request_succeeds_if_user_is_not_root_and_logged_in_user_can_create_organizations() {
settings.setProperty(ORGANIZATIONS_ANYONE_CAN_CREATE, true);
- userSession.login();
+ userSession.logIn();
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
verifyResponseAndDb(executeRequest("foo"), SOME_UUID, "foo", "foo", SOME_DATE);
public void request_creates_owners_group_with_all_permissions_for_new_organization_and_add_current_user_to_it() {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
UserDto user = dbTester.users().makeRoot(dbTester.users().insertUser());
- userSession.login(user).setRoot();
+ userSession.logIn(user).setRoot();
executeRequest("orgFoo");
public void request_creates_default_template_for_owner_group_and_anyone() {
mockForSuccessfulInsert(SOME_UUID, SOME_DATE);
UserDto user = dbTester.users().makeRoot(dbTester.users().insertUser());
- userSession.login(user).setRoot();
+ userSession.logIn(user).setRoot();
executeRequest("orgFoo");
}
private void makeUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
private void mockForSuccessfulInsert(String uuid, long now) {
@Test
public void request_fails_with_IAE_if_key_param_is_missing() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'key' parameter is missing");
@Test
public void request_fails_with_IAE_if_key_is_the_one_of_default_organization() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Default Organization can't be deleted");
@Test
public void request_fails_with_NotFoundException_if_organization_with_specified_key_does_not_exist() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("Organization with key 'foo' not found");
@Test
public void request_fails_with_ForbiddenException_when_user_has_no_System_Administer_permission() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void request_fails_with_ForbiddenException_when_user_does_not_have_System_Administer_permission_on_specified_organization() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login().addOrganizationPermission(dbTester.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(dbTester.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void request_deletes_specified_organization_if_exists_and_user_has_Admin_permission_on_it() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
sendRequest(organization);
@Test
public void request_deletes_specified_organization_if_exists_and_user_is_root() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
sendRequest(organization);
@Test
public void request_also_deletes_components_of_specified_organization() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
OrganizationDto organization = dbTester.organizations().insert();
ComponentDto project = dbTester.components().insertProject(organization);
@Test
public void request_also_deletes_permissions_templates_and_permissions_and_groups_of_specified_organization() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
OrganizationDto org = dbTester.organizations().insert();
OrganizationDto otherOrg = dbTester.organizations().insert();
@Test
public void request_fails_if_user_does_not_have_any_SYSTEM_ADMIN_permission() {
OrganizationDto dto = mockForSuccessfulUpdate(DATE_1, DATE_2);
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
public void request_fails_if_user_has_SYSTEM_ADMIN_permission_on_other_organization() {
OrganizationDto dto = dbTester.organizations().insert();
userSession.addOrganizationPermission(dbTester.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void request_fails_if_key_is_missing() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("The 'key' parameter is missing");
@Test
public void request_fails_if_name_is_one_char_long() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Name 'a' must be at least 2 chars long");
@Test
public void request_fails_if_name_is_65_chars_long() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Name '" + STRING_65_CHARS_LONG + "' must be at most 64 chars long");
@Test
public void request_fails_if_description_is_257_chars_long() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("description '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@Test
public void request_fails_if_url_is_257_chars_long() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("url '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
@Test
public void request_fails_if_avatar_is_257_chars_long() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("avatar '" + STRING_257_CHARS_LONG + "' must be at most 256 chars long");
}
private void giveUserSystemAdminPermission(OrganizationDto organizationDto) {
- userSession.login().addOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(organizationDto.getUuid(), SYSTEM_ADMIN);
}
private OrganizationDto mockForSuccessfulUpdate(long createdAt, long nextNow) {
}
private void verifyAuthorized(ComponentDto project, UserDto user) {
- logIn(user);
+ log_in(user);
verifyAuthorized(project, true);
}
private void verifyAuthorized(ComponentDto project, UserDto user, GroupDto group) {
- logIn(user).setGroups(group);
+ log_in(user).setGroups(group);
verifyAuthorized(project, true);
}
private void verifyNotAuthorized(ComponentDto project, UserDto user) {
- logIn(user);
+ log_in(user);
verifyAuthorized(project, false);
}
private void verifyNotAuthorized(ComponentDto project, UserDto user, GroupDto group) {
- logIn(user).setGroups(group);
+ log_in(user).setGroups(group);
verifyAuthorized(project, false);
}
assertThat(fooIndex.hasAccessToProject(project.uuid())).isEqualTo(expectedAccess);
}
- private UserSessionRule logIn(UserDto u) {
- userSession.login(u.getLogin()).setUserId(u.getId().intValue());
+ private UserSessionRule log_in(UserDto u) {
+ userSession.logIn(u.getLogin()).setUserId(u.getId().intValue());
return userSession;
}
public void adding_global_permission_fails_if_not_administrator_of_organization() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
// user is administrator of another organization
- userSession.login().addOrganizationPermission("anotherOrg", SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission("anotherOrg", SYSTEM_ADMIN);
expectedException.expect(ForbiddenException.class);
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertProject();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators");
ComponentDto project = db.components().insertProject();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
newRequest()
.setParam(PARAM_GROUP_NAME, group.getName())
@Test
public void adding_global_permission_fails_if_not_administrator_of_organization() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void adding_project_permission_fails_if_not_administrator_of_project() throws Exception {
ComponentDto project = db.components().insertProject();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
public void adding_project_permission_is_allowed_to_project_administrators() throws Exception {
ComponentDto project = db.components().insertProject();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
}
protected void loginAsAdmin(OrganizationDto org, OrganizationDto... otherOrgs) {
- userSession.login().addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
for (OrganizationDto otherOrg : otherOrgs) {
userSession.addOrganizationPermission(otherOrg.getUuid(), SYSTEM_ADMIN);
}
GroupDto groupWithoutPermission = db.users().insertGroup(organizationDto, "group-without-permission");
- userSession.login().addProjectUuidPermissions(ADMIN, "project-uuid");
+ userSession.logIn().addProjectUuidPermissions(ADMIN, "project-uuid");
String result = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, "project-uuid")
public void fail_if_insufficient_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSession.login("login");
+ userSession.logIn("login");
newRequest()
.setParam(PARAM_PERMISSION, "scan")
.execute();
@Test
public void removing_global_permission_fails_if_not_administrator_of_organization() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void removing_project_permission_fails_if_not_administrator_of_project() throws Exception {
ComponentDto project = db.components().insertProject();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
db.users().insertProjectPermissionOnGroup(aGroup, CODEVIEWER, project);
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, project);
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
newRequest()
.setParam(PARAM_GROUP_NAME, aGroup.getName())
.setParam(PARAM_PROJECT_ID, project.uuid())
@Test
public void removing_global_permission_fails_if_not_administrator_of_organization() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void removing_project_permission_fails_if_not_administrator_of_project() throws Exception {
ComponentDto project = db.components().insertProject();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
ComponentDto project = db.components().insertProject();
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project);
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project);
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
newRequest()
.setParam(PARAM_USER_LOGIN, user.getLogin())
import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN;
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN;
-import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
import static org.sonar.test.JsonAssert.assertJson;
public class SearchGlobalPermissionsActionTest extends BasePermissionWsTest<SearchGlobalPermissionsAction> {
@Test
public void fail_if_not_admin_of_default_organization() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Before
public void setUp() {
i18n.setProjectPermissions();
- userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
@Override
@Test
public void search_project_permissions_with_project_permission() throws Exception {
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid");
db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid"));
String result = newRequest()
@Test
public void fail_if_not_admin() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
// User has no permission
UserDto withoutPermission = db.users().insertUser(newUserDto());
- userSession.login().addProjectUuidPermissions(SYSTEM_ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(SYSTEM_ADMIN, project.uuid());
String result = newRequest()
.setParam(PARAM_PERMISSION, ISSUE_ADMIN)
.setParam(PARAM_PROJECT_ID, project.uuid())
@Test
public void fail_if_insufficient_privileges() throws Exception {
- userSession.login("login");
+ userSession.logIn("login");
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_not_admin_of_default_organization() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_not_admin_of_default_organization() throws Exception {
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_GATE_ADMIN);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_GATE_ADMIN);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_not_admin_of_default_organization() throws Exception {
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_PROFILE_ADMIN);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_PROFILE_ADMIN);
expectedException.expect(ForbiddenException.class);
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.sonar.api.config.MapSettings;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.component.ComponentDto;
@Test
public void fail_when_not_admin_of_organization() throws Exception {
- userSession.login().addOrganizationPermission("otherOrg", SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission("otherOrg", SYSTEM_ADMIN);
expectedException.expect(ForbiddenException.class);
- userSession.login().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
newRequest(template1.getUuid(), project.uuid(), null);
}
@Test
public void fail_if_not_admin() throws Exception {
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_PROFILE_ADMIN);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), QUALITY_PROFILE_ADMIN);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_uuid_is_not_known_without_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
@Test
public void fail_if_uuid_is_not_known_with_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
public void fail_to_delete_by_uuid_if_not_admin_without_views() throws Exception {
OrganizationDto organization = db.organizations().insert();
PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
public void fail_to_delete_by_uuid_if_not_admin_with_views() throws Exception {
OrganizationDto organization = db.organizations().insert();
PermissionTemplateDto template = insertTemplateAndAssociatedPermissions(organization);
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
public void fail_to_delete_by_name_if_not_admin_without_views() throws Exception {
OrganizationDto organization = db.organizations().insert();
PermissionTemplateDto template = db.permissionTemplates().insertTemplate(organization);
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
PermissionTemplateDto template = db.permissionTemplates().insertTemplate(PermissionTemplateTesting.newPermissionTemplateDto()
.setOrganizationUuid(organization.getUuid())
.setName("the name"));
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_neither_uuid_nor_name_is_provided_without_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_neither_uuid_nor_name_is_provided_with_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_both_uuid_and_name_are_provided_without_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(BadRequestException.class);
@Test
public void fail_if_both_uuid_and_name_are_provided_with_views() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(BadRequestException.class);
// }
private UserSessionRule loginAsAdmin(OrganizationDto organization) {
- return userSession.login().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
+ return userSession.logIn().addOrganizationPermission(organization.getUuid(), SYSTEM_ADMIN);
}
private void runOnAllUnderTests(ConsumerWithException<WsActionTester> consumer) throws Exception {
@Test
public void fail_if_insufficient_privileges() throws Exception {
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_insufficient_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSession.login().setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
newRequest()
.setParam(PARAM_PERMISSION, UserRole.ADMIN)
@Test
public void fail_if_insufficient_privileges() throws Exception {
expectedException.expect(ForbiddenException.class);
- userSession.login("john").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSession.logIn("john").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
newRequest(user.getLogin(), template.getUuid(), DEFAULT_PERMISSION);
}
SearchTemplatesDataLoader dataLoaderWithViews = new SearchTemplatesDataLoader(dbClient, defaultTemplatesResolverWithViews);
underTestWithoutViews = new WsActionTester(new SearchTemplatesAction(dbClient, userSession, i18n, newPermissionWsSupport(), dataLoaderWithViews));
i18n.setProjectPermissions();
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
}
@Test
public void fail_if_not_admin() throws Exception {
OrganizationDto organization = db.organizations().insert();
PermissionTemplateDto template = insertTemplate(organization);
- userSession.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_insufficient_privileges() throws Exception {
PermissionTemplateDto template1 = addTemplateToDefaultOrganization();
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_insufficient_privileges() throws Exception {
PermissionTemplateDto template = addTemplateToDefaultOrganization();
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
@Test
public void fail_if_not_admin() throws Exception {
- userSession.login().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
+ userSession.logIn().addOrganizationPermission(db.getDefaultOrganization().getUuid(), SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
public class InfoActionTest {
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone().login("login")
+ public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn("login")
.setName("name");
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
@Test
public void request_fails_in_production_mode_with_ForbiddenException_when_user_is_not_root() {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
@Test
public void calls_ProcessCommandWrapper_requestForSQRestart_in_production_mode() throws Exception {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
actionTester.newRequest().execute();
@Test
public void logs_login_of_authenticated_user_requesting_the_restart_in_production_mode() throws Exception {
String login = "BigBother";
- userSessionRule.login(login).setRoot();
+ userSessionRule.logIn(login).setRoot();
actionTester.newRequest().execute();
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void triggers_cancel_for_downloads_and_uninstalls() throws Exception {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
underTest.handle(request, response);
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
WsTester wsTester = new WsTester(serverTester.get(PluginsWs.class));
// 1 - check what's installed, available and pending
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
" \"plugins\": [" +
" {" +
wsTester = restartServerTester();
// 4 - make sure plugin is installed
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
" \"plugins\": [" +
" {" +
wsTester = restartServerTester();
// 7 - make sure plugin has been uninstalled
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
wsTester.newGetRequest("api/plugins", "installed").execute().assertJson("{" +
" \"plugins\": [" +
" {" +
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
}
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_root() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
underTest.handle(request, response);
}
private void makeAuthenticatedUserRoot() {
- userSession.login().setRoot();
+ userSession.logIn().setRoot();
}
}
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
package org.sonar.server.project.ws;
import com.google.common.base.Throwables;
private ComponentUpdater componentUpdater = mock(ComponentUpdater.class, Mockito.RETURNS_MOCKS);
private WsActionTester ws = new WsActionTester(
- new CreateAction(
- db.getDbClient(), userSession,
- componentUpdater,
- defaultOrganizationProvider));
+ new CreateAction(
+ db.getDbClient(), userSession,
+ componentUpdater,
+ defaultOrganizationProvider));
@Test
public void create_project() throws Exception {
expectSuccessfulCallToComponentUpdater();
CreateWsResponse response = call(CreateRequest.builder()
- .setKey(DEFAULT_PROJECT_KEY)
- .setName(DEFAULT_PROJECT_NAME)
- .build());
+ .setKey(DEFAULT_PROJECT_KEY)
+ .setName(DEFAULT_PROJECT_NAME)
+ .build());
assertThat(response.getProject().getKey()).isEqualTo(DEFAULT_PROJECT_KEY);
assertThat(response.getProject().getName()).isEqualTo(DEFAULT_PROJECT_NAME);
userSession.setGlobalPermissions(PROVISIONING);
call(CreateRequest.builder()
- .setKey(DEFAULT_PROJECT_KEY)
- .setName(DEFAULT_PROJECT_NAME)
- .setBranch("origin/master")
- .build());
+ .setKey(DEFAULT_PROJECT_KEY)
+ .setName(DEFAULT_PROJECT_NAME)
+ .setBranch("origin/master")
+ .build());
NewComponent called = verifyCallToComponentUpdater();
assertThat(called.key()).isEqualTo(DEFAULT_PROJECT_KEY);
userSession.setGlobalPermissions(PROVISIONING);
ws.newRequest()
- .setMethod(POST.name())
- .setParam("key", DEFAULT_PROJECT_KEY)
- .setParam(PARAM_NAME, DEFAULT_PROJECT_NAME)
- .execute();
+ .setMethod(POST.name())
+ .setParam("key", DEFAULT_PROJECT_KEY)
+ .setParam(PARAM_NAME, DEFAULT_PROJECT_NAME)
+ .execute();
NewComponent called = verifyCallToComponentUpdater();
assertThat(called.key()).isEqualTo(DEFAULT_PROJECT_KEY);
expectedException.expect(BadRequestException.class);
call(CreateRequest.builder()
- .setKey(DEFAULT_PROJECT_KEY)
- .setName(DEFAULT_PROJECT_NAME)
- .build());
+ .setKey(DEFAULT_PROJECT_KEY)
+ .setName(DEFAULT_PROJECT_NAME)
+ .build());
}
@Test
expectSuccessfulCallToComponentUpdater();
String result = ws.newRequest()
- .setParam("key", DEFAULT_PROJECT_KEY)
- .setParam("name", DEFAULT_PROJECT_NAME)
- .execute().getInput();
+ .setParam("key", DEFAULT_PROJECT_KEY)
+ .setParam("name", DEFAULT_PROJECT_NAME)
+ .execute().getInput();
assertJson(result).isSimilarTo(getClass().getResource("create-example.json"));
}
private CreateWsResponse call(CreateRequest request) {
TestRequest httpRequest = ws.newRequest()
- .setMethod(POST.name())
- .setMediaType(MediaTypes.PROTOBUF);
+ .setMethod(POST.name())
+ .setMediaType(MediaTypes.PROTOBUF);
setNullable(request.getKey(), e -> httpRequest.setParam("project", e));
setNullable(request.getName(), e -> httpRequest.setParam("name", e));
setNullable(request.getBranch(), e -> httpRequest.setParam("branch", e));
@Before
public void setUp() {
ws = new WsTester(new ProjectsWs(
- new DeleteAction(
- componentCleanerService,
- new ComponentFinder(dbClient),
- dbClient,
- userSessionRule)));
+ new DeleteAction(
+ componentCleanerService,
+ new ComponentFinder(dbClient),
+ dbClient,
+ userSessionRule)));
}
@Test
public void global_admin_deletes_project_by_id() throws Exception {
ComponentDto project = componentDbTester.insertProject();
- userSessionRule.login().setGlobalPermissions(UserRole.ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(UserRole.ADMIN);
WsTester.TestRequest request = newRequest().setParam(PARAM_ID, project.uuid());
call(request);
public void global_admin_deletes_project_by_key() throws Exception {
ComponentDto project = componentDbTester.insertProject();
- userSessionRule.login().setGlobalPermissions(UserRole.ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(UserRole.ADMIN);
call(newRequest().setParam(PARAM_KEY, project.key()));
assertThat(verifyDeletedKey()).isEqualTo(project.key());
@Test
public void project_administrator_deletes_the_project_by_uuid() throws Exception {
ComponentDto project = componentDbTester.insertProject();
- userSessionRule.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSessionRule.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
call(newRequest().setParam(PARAM_ID, project.uuid()));
@Test
public void project_administrator_deletes_the_project_by_key() throws Exception {
ComponentDto project = componentDbTester.insertProject();
- userSessionRule.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSessionRule.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
call(newRequest().setParam(PARAM_KEY, project.key()));
public void return_403_if_not_project_admin_nor_org_admin() throws Exception {
ComponentDto project = componentDbTester.insertProject();
- userSessionRule.login().addProjectUuidPermissions(project.uuid(), UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN, UserRole.USER);
+ userSessionRule.logIn().addProjectUuidPermissions(project.uuid(), UserRole.CODEVIEWER, UserRole.ISSUE_ADMIN, UserRole.USER);
expectedException.expect(ForbiddenException.class);
call(newRequest().setParam(PARAM_ID, project.uuid()));
ComponentDto ghost1 = insertGhostProject(organization);
ComponentDto ghost2 = insertGhostProject(organization);
ComponentDto activeProject = insertActiveProject(organization);
- userSessionRule.login().addOrganizationPermission(organization, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organization, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organization.getKey())
int count = i;
insertGhostProject(organization, dto -> dto.setKey("ghost-key-" + count));
}
- userSessionRule.login().addOrganizationPermission(organization, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organization, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organization.getKey())
public void ghost_projects_with_chosen_fields() throws Exception {
OrganizationDto organization = db.organizations().insert();
insertGhostProject(organization);
- userSessionRule.login().addOrganizationPermission(organization, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organization, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organization.getKey())
insertGhostProject(organization, dto -> dto.setName("ghost-name-11"));
insertGhostProject(organization, dto -> dto.setName("ghost-name-20"));
- userSessionRule.login().addOrganizationPermission(organization, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organization, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organization.getKey())
OrganizationDto organization = db.organizations().insert();
insertGhostProject(organization, dto -> dto.setKey("ghost-key-1"));
- userSessionRule.login().addOrganizationPermission(organization, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organization, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organization.getKey())
dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(roslynProject)
.setStatus(STATUS_UNPROCESSED));
db.getSession().commit();
- userSessionRule.login().addOrganizationPermission(organizationDto, SYSTEM_ADMIN);
+ userSessionRule.logIn().addOrganizationPermission(organizationDto, SYSTEM_ADMIN);
TestResponse result = underTest.newRequest()
.setParam("organization", organizationDto.getKey())
@Test(expected = ForbiddenException.class)
public void fail_if_does_not_have_sufficient_rights() throws Exception {
- userSessionRule.login()
+ userSessionRule.logIn()
.addOrganizationPermission(db.getDefaultOrganization(), UserRole.USER)
.addOrganizationPermission(db.getDefaultOrganization(), UserRole.ISSUE_ADMIN)
.addOrganizationPermission(db.getDefaultOrganization(), UserRole.CODEVIEWER);
public void fail_with_NotFoundException_when_organization_with_specified_key_does_not_exist() {
TestRequest request = underTest.newRequest()
.setParam("organization", "foo");
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("No organization for key 'foo'");
@Before
public void setUp() {
user = db.users().insertUser("john");
- userSession.login(user);
+ userSession.logIn(user);
}
@Test
ComponentDto analyzedProject = ComponentTesting.newProjectDto(organizationDto, "analyzed-uuid-1");
db.components().insertComponents(newProvisionedProject(organizationDto, "1"), newProvisionedProject(organizationDto, "2"), analyzedProject);
db.components().insertSnapshot(SnapshotTesting.newAnalysis(analyzedProject));
- userSessionRule.login().addOrganizationPermission(organizationDto, GlobalPermissions.PROVISIONING);
+ userSessionRule.logIn().addOrganizationPermission(organizationDto, GlobalPermissions.PROVISIONING);
TestResponse result = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, organizationDto.getKey())
for (int i = 1; i <= 10; i++) {
db.components().insertComponent(newProvisionedProject(organizationDto, String.valueOf(i)));
}
- userSessionRule.login().addOrganizationPermission(organizationDto, GlobalPermissions.PROVISIONING);
+ userSessionRule.logIn().addOrganizationPermission(organizationDto, GlobalPermissions.PROVISIONING);
TestRequest request = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, organizationDto.getKey())
public void provisioned_projects_with_desired_fields() throws Exception {
OrganizationDto organization = db.organizations().insert();
db.components().insertComponent(newProvisionedProject(organization, "1"));
- userSessionRule.login().addOrganizationPermission(organization, GlobalPermissions.PROVISIONING);
+ userSessionRule.logIn().addOrganizationPermission(organization, GlobalPermissions.PROVISIONING);
String jsonOutput = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
public void provisioned_projects_with_query() throws Exception {
OrganizationDto organization = db.organizations().insert();
db.components().insertComponents(newProvisionedProject(organization, "1"), newProvisionedProject(organization, "2"));
- userSessionRule.login().addOrganizationPermission(organization, GlobalPermissions.PROVISIONING);
+ userSessionRule.logIn().addOrganizationPermission(organization, GlobalPermissions.PROVISIONING);
String jsonOutput = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, organization.getKey())
.setName("Roslyn")
.setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100"));
db.components().insertComponents(hBaseProject, roslynProject);
- userSessionRule.login().addOrganizationPermission(organizationDto.getUuid(), GlobalPermissions.PROVISIONING);
+ userSessionRule.logIn().addOrganizationPermission(organizationDto.getUuid(), GlobalPermissions.PROVISIONING);
TestResponse result = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, organizationDto.getKey())
public void fail_when_not_enough_privileges() throws Exception {
OrganizationDto organizationDto = db.organizations().insert();
db.components().insertComponent(newProvisionedProject(organizationDto, "1"));
- userSessionRule.login().addOrganizationPermission(organizationDto.getUuid(), GlobalPermissions.SCAN_EXECUTION);
+ userSessionRule.logIn().addOrganizationPermission(organizationDto.getUuid(), GlobalPermissions.SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
public void fail_with_NotFoundException_when_organization_with_specified_key_does_not_exist() {
TestRequest request = underTest.newRequest()
.setParam(PARAM_ORGANIZATION, "foo");
- userSessionRule.login();
+ userSessionRule.logIn();
expectedException.expect(NotFoundException.class);
expectedException.expectMessage("No organization for key 'foo'");
@Before
public void setUp() {
user = db.users().insertUser();
- userSession.login(user);
+ userSession.logIn(user);
alertStatusMetric = dbClient.metricDao().insert(dbSession, newMetricDto().setKey(ALERT_STATUS_KEY).setValueType(ValueType.LEVEL.name()));
db.commit();
underTest = new CreateAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
}
@Test
ComponentDto project = insertProject();
String result = ws.newRequest()
- .setMethod("POST")
- .setParam(PARAM_PROJECT_KEY, project.key())
- .setParam(PARAM_NAME, "Custom")
- .setParam(PARAM_URL, "http://example.org")
- .execute().getInput();
+ .setMethod("POST")
+ .setParam(PARAM_PROJECT_KEY, project.key())
+ .setParam(PARAM_NAME, "Custom")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute().getInput();
assertJson(result).ignoreFields("id").isSimilarTo(getClass().getResource("create-example.json"));
}
ComponentDto project = insertProject();
String result = ws.newRequest()
- .setMethod("POST")
- .setParam(PARAM_PROJECT_ID, project.uuid())
- .setParam(PARAM_NAME, "Custom")
- .setParam(PARAM_URL, "http://example.org")
- .execute().getInput();
+ .setMethod("POST")
+ .setParam(PARAM_PROJECT_ID, project.uuid())
+ .setParam(PARAM_NAME, "Custom")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute().getInput();
assertJson(result).ignoreFields("id").isSimilarTo(getClass().getResource("create-example.json"));
}
@Test
public void global_admin() throws IOException {
- userSession.login().setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn().setGlobalPermissions(SYSTEM_ADMIN);
ComponentDto project = insertProject();
createAndTest(project);
}
@Test
public void require_project_admin() throws IOException {
- userSession.login();
+ userSession.logIn();
ComponentDto project = insertProject();
userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
createAndTest(project);
public void fail_if_no_name() {
expectedException.expect(IllegalArgumentException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, "unknown")
- .setParam(PARAM_URL, "http://example.org")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, "unknown")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute();
}
@Test
public void fail_if_long_name() {
expectedException.expect(IllegalArgumentException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, "unknown")
- .setParam(PARAM_NAME, StringUtils.leftPad("", 129, "*"))
- .setParam(PARAM_URL, "http://example.org")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, "unknown")
+ .setParam(PARAM_NAME, StringUtils.leftPad("", 129, "*"))
+ .setParam(PARAM_URL, "http://example.org")
+ .execute();
}
@Test
public void fail_if_no_url() {
expectedException.expect(IllegalArgumentException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, "unknown")
- .setParam(PARAM_NAME, "Custom")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, "unknown")
+ .setParam(PARAM_NAME, "Custom")
+ .execute();
}
@Test
public void fail_if_long_url() {
expectedException.expect(IllegalArgumentException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, "unknown")
- .setParam(PARAM_NAME, "random")
- .setParam(PARAM_URL, StringUtils.leftPad("", 2049, "*"))
- .execute();
+ .setParam(PARAM_PROJECT_KEY, "unknown")
+ .setParam(PARAM_NAME, "random")
+ .setParam(PARAM_URL, StringUtils.leftPad("", 2049, "*"))
+ .execute();
}
@Test
public void fail_when_no_project() {
expectedException.expect(NotFoundException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, "unknown")
- .setParam(PARAM_NAME, "Custom")
- .setParam(PARAM_URL, "http://example.org")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, "unknown")
+ .setParam(PARAM_NAME, "Custom")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute();
}
@Test
expectedException.expect(ForbiddenException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
- .setParam(PARAM_NAME, "Custom")
- .setParam(PARAM_URL, "http://example.org")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
+ .setParam(PARAM_NAME, "Custom")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute();
}
@Test
public void fail_if_not_project_admin() {
- userSession.login();
+ userSession.logIn();
insertProject();
expectedException.expect(ForbiddenException.class);
ws.newRequest()
- .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
- .setParam(PARAM_NAME, "Custom")
- .setParam(PARAM_URL, "http://example.org")
- .execute();
+ .setParam(PARAM_PROJECT_KEY, PROJECT_KEY)
+ .setParam(PARAM_NAME, "Custom")
+ .setParam(PARAM_URL, "http://example.org")
+ .execute();
}
private ComponentDto insertProject() {
OrganizationDto org = db.organizations().insert();
return db.components().insertComponent(
- ComponentTesting.newProjectDto(org, PROJECT_UUID).setKey(PROJECT_KEY));
+ ComponentTesting.newProjectDto(org, PROJECT_UUID).setKey(PROJECT_KEY));
}
private void createAndTest(ComponentDto project, String name, String url, String type) throws IOException {
InputStream responseStream = ws.newRequest()
- .setMethod("POST")
- .setParam(PARAM_PROJECT_KEY, project.key())
- .setParam(PARAM_NAME, name)
- .setParam(PARAM_URL, url)
- .setMediaType(PROTOBUF)
- .execute().getInputStream();
+ .setMethod("POST")
+ .setParam(PARAM_PROJECT_KEY, project.key())
+ .setParam(PARAM_NAME, name)
+ .setParam(PARAM_URL, url)
+ .setMediaType(PROTOBUF)
+ .execute().getInputStream();
WsProjectLinks.CreateWsResponse response = WsProjectLinks.CreateWsResponse.parseFrom(responseStream);
underTest = new DeleteAction(dbClient, userSession);
ws = new WsActionTester(underTest);
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
}
@Test
@Test
public void project_admin() throws IOException {
- userSession.login("login");
+ userSession.logIn("login");
ComponentDto project = insertProject();
userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
@Test
public void fail_if_not_project_admin() {
- userSession.login("login");
+ userSession.logIn("login");
ComponentDto project = insertProject();
ComponentLinkDto link = insertCustomLink(project.uuid());
underTest = new SearchAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
}
@Test
@Test
public void global_admin() throws IOException {
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
checkItWorks();
}
@Test
public void project_admin() throws IOException {
- userSession.login("login");
+ userSession.logIn("login");
ComponentDto project = insertProject();
userSession.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
checkItWorks(project);
@Test
public void project_user() throws IOException {
- userSession.login("login");
+ userSession.logIn("login");
ComponentDto project = insertProject();
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid());
checkItWorks(project);
@Test
public void does_not_fail_when_user_has_not_project_browse_permission() throws Exception {
- userSession.login("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+ userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
definitions.addComponent(PropertyDefinition.builder("foo").build());
propertyDb.insertProperties(newComponentPropertyDto(project).setKey("foo").setValue("one"));
}
private void setAuthenticatedUser() {
- userSession.login("user");
+ userSession.logIn("user");
}
private void setUserWithBrowsePermissionOnProject() {
- userSession.login("user").addProjectUuidPermissions(USER, project.uuid());
+ userSession.logIn("user").addProjectUuidPermissions(USER, project.uuid());
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private void setUserAsProjectAdmin() {
- userSession.login("project-admin")
+ userSession.logIn("project-admin")
.addProjectUuidPermissions(ADMIN, project.uuid())
.addProjectUuidPermissions(USER, project.uuid());
}
// User can only see project 1
dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, project1);
- userSession.login(user.getLogin()).setUserId(user.getId().intValue());
+ userSession.logIn(user.getLogin()).setUserId(user.getId().intValue());
Association result = underTest.find(
builder()
.gateId(Long.toString(qGate.getId()))
@Test
public void return_edit_to_false_when_not_quality_gate_permission() throws Exception {
- userSession.login("not-admin").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn("not-admin").setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
AppWsResponse response = executeRequest();
@Test
public void return_edit_to_true_when_quality_gate_permission() throws Exception {
- userSession.login("admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
AppWsResponse response = executeRequest();
}
private void setUserAsQualityGateAdmin() {
- userSession.login("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
}
private void setUserAsNotQualityGateAdmin() {
- userSession.login("not-admin").setGlobalPermissions(SCAN_EXECUTION);
+ userSession.logIn("not-admin").setGlobalPermissions(SCAN_EXECUTION);
}
}
}
private void setUserAsQualityGateAdmin() {
- userSession.login("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
}
private void setUserAsNotQualityGateAdmin() {
- userSession.login("not-admin").setGlobalPermissions(SCAN_EXECUTION);
+ userSession.logIn("not-admin").setGlobalPermissions(SCAN_EXECUTION);
}
}
underTest = new DeselectAction(qualityGates, dbClient, componentFinder);
ws = new WsActionTester(underTest);
- userSession.login("login").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(QUALITY_GATE_ADMIN);
}
@Test
String gateId = String.valueOf(gate.getId());
associateProjectToQualityGate(project.getId(), gateId);
- userSession.login("login").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
callByKey(gateId, project.getKey());
String gateId = String.valueOf(gate.getId());
associateProjectToQualityGate(project.getId(), gateId);
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
callByKey(gateId, project.getKey());
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
expectedException.expect(ForbiddenException.class);
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
expectedException.expect(ForbiddenException.class);
@Test
public void get_with_project_admin_permission() {
ComponentDto project = componentDb.insertProject();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
@Test
public void get_with_project_user_permission() {
ComponentDto project = componentDb.insertProject();
- userSession.login().addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
QualityGateDto dbQualityGate = insertQualityGate("Sonar way");
setDefaultQualityGate(dbQualityGate.getId());
underTest = new SelectAction(dbClient, userSession, componentFinder);
ws = new WsActionTester(underTest);
- userSession.login("login").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(QUALITY_GATE_ADMIN);
}
@Test
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
callByKey(gateId, project.getKey());
assertSelected(gateId, project.getId());
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(SYSTEM_ADMIN);
callByKey(gateId, project.getKey());
assertSelected(gateId, project.getId());
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
+ userSession.logIn("login").addProjectUuidPermissions(UserRole.ISSUE_ADMIN, project.uuid());
expectedException.expect(ForbiddenException.class);
callByKey(gateId, project.getKey());
QualityGateDto gate = insertQualityGate();
String gateId = String.valueOf(gate.getId());
- userSession.login("login").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("login").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
expectedException.expect(ForbiddenException.class);
callByKey(gateId, project.getKey());
}
private void setUserAsQualityGateAdmin() {
- userSession.login("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
+ userSession.logIn("project-admin").setGlobalPermissions(QUALITY_GATE_ADMIN);
}
private void setUserAsNotQualityGateAdmin() {
- userSession.login("not-admin").setGlobalPermissions(SCAN_EXECUTION);
+ userSession.logIn("not-admin").setGlobalPermissions(SCAN_EXECUTION);
}
}
@Test
public void count_by_all_profiles() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
service.activate(XOO_P1_KEY, new RuleActivation(RuleTesting.XOO_X1).setSeverity("BLOCKER"));
service.activate(XOO_P2_KEY, new RuleActivation(RuleTesting.XOO_X1).setSeverity("BLOCKER"));
@Test
public void count_by_all_deprecated_profiles() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
RuleDto xooRule2 = newXooX2().setStatus(RuleStatus.DEPRECATED);
RuleDto xooRule3 = newXooX3().setStatus(RuleStatus.DEPRECATED);
@Test
public void stat_for_all_profiles() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
service.activate(XOO_P1_KEY, new RuleActivation(RuleTesting.XOO_X1).setSeverity("MINOR"));
service.activate(XOO_P2_KEY, new RuleActivation(RuleTesting.XOO_X1).setSeverity("BLOCKER"));
@Test
public void count_by_deprecated() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
// create deprecated rule
RuleDto deprecatedXooRule = RuleTesting.newDto(RuleKey.of("xoo", "deprecated1"))
activation.setSeverity(BLOCKER);
activation.setParameter("max", "7");
activation.setParameter("min", "3");
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
List<ActiveRuleChange> changes = ruleActivator.activate(dbSession, activation, profileDto);
dbSession.commit();
dbSession.clearCache();
RuleActivation activation = new RuleActivation(XOO_X1);
activation.setSeverity(BLOCKER);
activation.setParameter("max", "7");
- userSessionRule.login();
+ userSessionRule.logIn();
activate(activation, XOO_P1_KEY);
// deactivation
@Test
public void propagate_activation_update_on_child_profiles() {
createChildProfiles();
- userSessionRule.login();
+ userSessionRule.logIn();
// activate on root profile
RuleActivation activation = new RuleActivation(XOO_X1);
}
private void setUserAsQualityProfileAdmin() {
- userSession.login("admin").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
}
private void executeRequest(ComponentDto project, QualityProfileDto qualityProfile) {
ruleIndexer = tester.get(RuleIndexer.class);
activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
ruleIndex = tester.get(RuleIndex.class);
- userSessionRule.login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
}
@After
@Test(expected = ForbiddenException.class)
public void fail_if_missing_permission() throws Exception {
- userSessionRule.login("anakin");
+ userSessionRule.logIn("anakin");
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent")
.setParam(QProfileRef.PARAM_PROFILE_KEY, "polop")
.setParam("parentKey", "pulup")
@Test
public void copy_nominal() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
String fromProfileKey = "xoo-sonar-way-23456";
String toName = "Other Sonar Way";
@Test
public void copy_with_parent() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
String fromProfileKey = "xoo-sonar-way-23456";
String toName = "Other Sonar Way";
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_key() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "copy")
.setParam("name", "Other Sonar Way")
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_name() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "copy")
.setParam("key", "sonar-way-xoo1-13245")
@Test(expected = ForbiddenException.class)
public void fail_on_missing_permission() throws Exception {
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
tester.newPostRequest("api/qualityprofiles", "copy")
.setParam("key", "sonar-way-xoo1-13245")
}
private void setUserAsQualityProfileAdmin() {
- userSession.login("admin").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
}
private ProfileImporter[] createImporters() {
qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session);
session.commit();
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("profileKey", "sonar-way-xoo1-12345").execute().assertNoContent();
qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session);
session.commit();
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("profileName", "Sonar way").setParam("language", xoo1.getKey()).execute().assertNoContent();
@Test(expected = ForbiddenException.class)
public void fail_on_missing_permission() throws Exception {
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
tester.newPostRequest("api/qualityprofiles", "delete").execute();
}
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_arguments() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").execute();
}
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_language() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("profileName", "Polop").execute();
}
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_name() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("language", xoo1.getKey()).execute();
}
@Test(expected = IllegalArgumentException.class)
public void fail_on_too_many_arguments() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("profileName", "Polop").setParam("language", xoo1.getKey()).setParam("profileKey", "polop").execute();
}
@Test(expected = NotFoundException.class)
public void fail_on_unexisting_profile() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "delete").setParam("profileName", "Polop").setParam("language", xoo1.getKey()).execute();
}
}
public void setUp() {
organizationDto = db.organizations().insert();
user = db.users().insertUser(UserTesting.newUserDto().setLogin("obiwan"));
- userSessionRule.login("obiwan").setUserId(user.getId().intValue());
+ userSessionRule.logIn("obiwan").setUserId(user.getId().intValue());
createProfiles();
@Rule
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester)
- .login("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ .logIn("gandalf").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QProfilesWs ws;
DbClient db;
@Test
public void rename_nominal() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("key", "sonar-way-xoo2-23456")
@Test(expected = BadRequestException.class)
public void do_nothing_on_conflict() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("key", "sonar-way-xoo2-23456")
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_key() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("name", "Other Sonar Way")
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_name() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("key", "sonar-way-xoo1-13245")
@Test(expected = ForbiddenException.class)
public void fail_on_missing_permission() throws Exception {
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("key", "sonar-way-xoo1-13245")
@Test(expected = NotFoundException.class)
public void fail_on_unknown_profile() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "rename")
.setParam("key", "polop")
@Test
public void restore_profile() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
QualityProfileDto profile = QualityProfileDto.createFor("xoo-sonar-way-12345")
.setDefault(false).setLanguage("xoo").setName("Sonar way");
@Test(expected = IllegalArgumentException.class)
public void fail_on_missing_backup() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "restore").execute();
}
@Test(expected = ForbiddenException.class)
public void fail_on_misssing_permission() throws Exception {
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
tester.newPostRequest("api/qualityprofiles", "restore").setParam("backup", "<polop><palap/></polop>").execute();
}
@Test
public void return_empty_result_when_no_info_or_warning() {
- userSession.login("himself").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("himself").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
TestResponse response = tester.newRequest().setParam("language", "xoo").execute();
verify(reset).resetLanguage("xoo");
@Test
public void fail_on_unknown_language() throws Exception {
- userSession.login("himself").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
+ userSession.logIn("himself").setGlobalPermissions(QUALITY_PROFILE_ADMIN);
expectedException.expect(IllegalArgumentException.class);
tester.newRequest().setParam("language", "unknown").execute();
}
@Test
public void set_default_profile_using_key() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
checkDefaultProfile(xoo1Key, "sonar-way-xoo1-12345");
checkDefaultProfile(xoo2Key, "my-sonar-way-xoo2-34567");
@Test
public void set_default_profile_using_language_and_name() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
tester.newPostRequest("api/qualityprofiles", "set_default").setParam("language", xoo2Key).setParam("profileName", "Sonar way").execute().assertNoContent();
@Test
public void fail_to_set_default_profile_using_key() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
try {
tester.newPostRequest("api/qualityprofiles", "set_default").setParam("profileKey", "unknown-profile-666").execute();
@Test
public void fail_to_set_default_profile_using_language_and_name() throws Exception {
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
try {
tester.newPostRequest("api/qualityprofiles", "set_default").setParam("language", xoo2Key).setParam("profileName", "Unknown").execute();
@Test
public void fail_on_missing_permission() throws Exception {
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
try {
tester.newPostRequest("api/qualityprofiles", "set_default").setParam("profileKey", "sonar-way-xoo2-23456").execute().assertNoContent();
@Test
public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
- userSessionRule.login();
+ userSessionRule.logIn();
expectInsufficientPrivilegesForbiddenException();
}
private UserSessionRule makeAuthenticatedUserRoot() {
- return userSessionRule.login().setRoot();
+ return userSessionRule.logIn().setRoot();
}
private List<WsRoot.Root> executeRequest() {
@Test
public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
- userSessionRule.login();
+ userSessionRule.logIn();
expectInsufficientPrivilegesForbiddenException();
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
private void expectInsufficientPrivilegesForbiddenException() {
@Test
public void execute_fails_with_ForbiddenException_when_user_is_not_root() {
- userSessionRule.login();
+ userSessionRule.logIn();
expectInsufficientPrivilegesForbiddenException();
}
private void makeAuthenticatedUserRoot() {
- userSessionRule.login().setRoot();
+ userSessionRule.logIn().setRoot();
}
private void expectInsufficientPrivilegesForbiddenException() {
});
// Create a profile and activate rule
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
dbSession.commit();
dbSession.clearCache();
register(rules);
// create a profile and activate rule
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
dbSession.commit();
dbSession.clearCache();
});
// Create profile and activate rule
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1());
dbSession.commit();
dbSession.clearCache();
@Test
public void delete_throws_ForbiddenException_if_not_administrator() {
- userSessionRule.login().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSessionRule.logIn().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void set_markdown_note() {
- userSessionRule.login("me");
+ userSessionRule.logIn("me");
ruleDao.insert(dbSession, RuleTesting.newDto(RULE_KEY)
.setNoteData(null)
public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login()
+ public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn()
.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
WsTester wsTester;
public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login()
+ public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn()
.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
WsTester wsTester;
public static ServerTester tester = new ServerTester().withEsIndexes();
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).login().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
+ public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester).logIn().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN);
WsTester wsTester;
@Test
public void fail_when_not_system_admin() throws Exception {
- userSession.login("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
+ userSession.logIn("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
expectedException.expect(ForbiddenException.class);
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
}
@Test
public void fail_when_user_has_not_project_browse_permission() throws Exception {
- userSession.login("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+ userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
propertyDefinitions.addComponent(PropertyDefinition.builder("foo").build());
expectedException.expect(ForbiddenException.class);
}
private void setAuthenticatedUser() {
- userSession.login("user");
+ userSession.logIn("user");
}
private void setUserWithBrowsePermissionOnProject() {
- userSession.login("user").addProjectUuidPermissions(USER, project.uuid());
+ userSession.logIn("user").addProjectUuidPermissions(USER, project.uuid());
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private void setUserAsProjectAdmin() {
- userSession.login("project-admin")
+ userSession.logIn("project-admin")
.addProjectUuidPermissions(ADMIN, project.uuid())
.addProjectUuidPermissions(USER, project.uuid());
}
@Test
public void fail_when_not_system_admin() throws Exception {
- userSession.login("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
+ userSession.logIn("not-admin").setGlobalPermissions(GlobalPermissions.QUALITY_GATE_ADMIN);
definitions.addComponent(PropertyDefinition.builder("foo").build());
expectedException.expect(ForbiddenException.class);
@Test
public void fail_when_not_project_admin() throws Exception {
- userSession.login("project-admin").addProjectUuidPermissions(USER, project.uuid());
+ userSession.logIn("project-admin").addProjectUuidPermissions(USER, project.uuid());
definitions.addComponent(PropertyDefinition.builder("foo").build());
expectedException.expect(ForbiddenException.class);
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private void setUserAsProjectAdmin() {
- userSession.login("project-admin").addProjectUuidPermissions(ADMIN, project.uuid());
+ userSession.logIn("project-admin").addProjectUuidPermissions(ADMIN, project.uuid());
}
private void assertGlobalPropertyDoesNotExist(String key) {
@Test
public void fail_when_user_has_not_project_browse_permission() throws Exception {
- userSession.login("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
+ userSession.logIn("project-admin").addProjectUuidPermissions(CODEVIEWER, project.uuid());
definitions.addComponent(PropertyDefinition.builder("foo").build());
expectedException.expect(ForbiddenException.class);
}
private void setAuthenticatedUser() {
- userSession.login("user");
+ userSession.logIn("user");
}
private void setUserWithBrowsePermissionOnProject() {
- userSession.login("user").addProjectUuidPermissions(USER, project.uuid());
+ userSession.logIn("user").addProjectUuidPermissions(USER, project.uuid());
}
private void setUserAsSystemAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private void setUserAsProjectAdmin() {
- userSession.login("project-admin")
+ userSession.logIn("project-admin")
.addProjectUuidPermissions(ADMIN, project.uuid())
.addProjectUuidPermissions(USER, project.uuid());
}
@Test
public void show_hashes() throws Exception {
db.prepareDbUnit(getClass(), "shared.xml");
- userSessionRule.login("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+ userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
assertThat(request.execute().outputAsString()).isEqualTo("987654");
@Test
public void show_hashes_on_test_file() throws Exception {
db.prepareDbUnit(getClass(), "show_hashes_on_test_file.xml");
- userSessionRule.login("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+ userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", "ActionTest.java");
assertThat(request.execute().outputAsString()).isEqualTo("987654");
@Test
public void hashes_empty_if_no_source() throws Exception {
db.prepareDbUnit(getClass(), "no_source.xml");
- userSessionRule.login("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+ userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
request.execute().assertNoContent();
@Test
public void fail_to_show_hashes_if_file_does_not_exist() {
- userSessionRule.login("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
+ userSessionRule.logIn("polop").addProjectUuidPermissions(UserRole.USER, PROJECT_UUID);
try {
WsTester.TestRequest request = tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY);
request.execute();
public void fail_on_missing_permission() throws Exception {
db.prepareDbUnit(getClass(), "shared.xml");
- userSessionRule.login("polop");
+ userSessionRule.logIn("polop");
tester.newGetRequest("api/sources", "hash").setParam("key", COMPONENT_KEY).execute();
}
}
public void should_check_permission() throws Exception {
insertFileWithData(FileSourceTesting.newFakeData(1).build());
- userSessionRule.login("login");
+ userSessionRule.logIn("login");
wsTester.newGetRequest("api/sources", "lines")
.setParam("uuid", FILE_UUID)
}
private void setUserWithValidPermission() {
- userSessionRule.login("login").addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
+ userSessionRule.logIn("login").addProjectUuidPermissions(UserRole.CODEVIEWER, PROJECT_UUID);
}
private void insertFile() throws IOException {
* {@code UserSessionRule.standalone().anonymous()}.
* </p>
* <p>
- * To emulate an identified user, either use method {@link #login(String)} if you want to specify the user's login, or
- * method {@link #login()} which will do the same but using the value of {@link #DEFAULT_LOGIN} as the user's login
+ * To emulate an identified user, either use method {@link #logIn(String)} if you want to specify the user's login, or
+ * method {@link #logIn()} which will do the same but using the value of {@link #DEFAULT_LOGIN} as the user's login
* (use the latest override if you don't care about the actual value of the login, it will save noise in your test).
* </p>
*/
/**
* Log in with the default login {@link #DEFAULT_LOGIN}
*/
- public UserSessionRule login() {
- return login(DEFAULT_LOGIN);
+ public UserSessionRule logIn() {
+ return logIn(DEFAULT_LOGIN);
}
/**
* Log in with the specified login
*/
- public UserSessionRule login(String login) {
+ public UserSessionRule logIn(String login) {
setCurrentUserSession(new MockUserSession(login));
return this;
}
/**
* Log in with the specified login
*/
- public UserSessionRule login(UserDto userDto) {
+ public UserSessionRule logIn(UserDto userDto) {
setCurrentUserSession(new MockUserSession(userDto));
return this;
}
UserDto user = userDbTester.insertUser("obiwan");
componentDbTester.insertComponent(project);
propertyDbTester.insertProperty(new PropertyDto().setKey("favourite").setResourceId(project.getId()).setUserId(user.getId()));
- userSessionRule.login(user).addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSessionRule.logIn(user).addProjectUuidPermissions(UserRole.USER, project.uuid());
executeAndVerify(project.key(), "return_component_info_with_favourite.json");
}
public void return_configuration_for_admin() throws Exception {
UserDto user = userDbTester.insertUser();
componentDbTester.insertComponent(project);
- userSessionRule.login(user)
+ userSessionRule.logIn(user)
.addProjectUuidPermissions(UserRole.USER, "abcd")
.addProjectUuidPermissions(UserRole.ADMIN, "abcd");
createQProfile("qp2", "Sonar Way Xoo", "xoo"));
QualityGateDto qualityGateDto = dbTester.qualityGates().insertQualityGate("Sonar way");
dbTester.qualityGates().associateProjectToQualityGate(project, qualityGateDto);
- userSessionRule.login(user)
+ userSessionRule.logIn(user)
.addProjectUuidPermissions(UserRole.USER, project.uuid())
.addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
@Test
public void return_global_pages_for_user() throws Exception {
init(createPages(), new ResourceTypeTree[] {});
- userSessionRule.login("obiwan");
+ userSessionRule.logIn("obiwan");
executeAndVerify("global_pages_for_user.json");
}
@Test
public void return_global_pages_for_admin_user() throws Exception {
init(createPages(), new ResourceTypeTree[] {});
- userSessionRule.login("obiwan").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("obiwan").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
executeAndVerify("global_pages_for_admin.json");
}
public void verify_example() {
OrganizationDto defaultOrganization = dbTester.getDefaultOrganization();
- userSession.login().addOrganizationPermission(defaultOrganization.getUuid(), "admin");
+ userSession.logIn().addOrganizationPermission(defaultOrganization.getUuid(), "admin");
TestResponse response = executeRequest(defaultOrganization);
@Test
public void returns_non_admin_and_default_true_when_user_logged_in_but_not_admin_and_key_is_the_default_organization() {
- userSession.login();
+ userSession.logIn();
TestResponse response = executeRequest(dbTester.getDefaultOrganization());
@Test
public void returns_admin_and_default_true_when_user_logged_in_and_admin_and_key_is_the_default_organization() {
OrganizationDto defaultOrganization = dbTester.getDefaultOrganization();
- userSession.login().addOrganizationPermission(defaultOrganization.getUuid(), "admin");
+ userSession.logIn().addOrganizationPermission(defaultOrganization.getUuid(), "admin");
TestResponse response = executeRequest(defaultOrganization);
@Test
public void returns_non_admin_and_default_false_when_user_logged_in_but_not_admin_and_key_is_not_the_default_organization() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login();
+ userSession.logIn();
TestResponse response = executeRequest(organization);
@Test
public void returns_admin_and_default_false_when_user_logged_in_and_admin_and_key_is_not_the_default_organization() {
OrganizationDto organization = dbTester.organizations().insert();
- userSession.login().addOrganizationPermission(organization.getUuid(), "admin");
+ userSession.logIn().addOrganizationPermission(organization.getUuid(), "admin");
TestResponse response = executeRequest(organization);
@Test
public void fail_if_not_system_admin() throws Exception {
- userSession.login().setGlobalPermissions(PROVISIONING);
+ userSession.logIn().setGlobalPermissions(PROVISIONING);
expectedException.expect(ForbiddenException.class);
call(newInputStream(plugin.toPath()), PLUGIN_NAME);
}
private void setSystemAdminUser() {
- userSession.login().setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn().setGlobalPermissions(SYSTEM_ADMIN);
}
private void assertPluginIsUploaded(String pluginName) {
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
private WsTester tester;
private DbClient dbClient;
public void fail_on_missing_permission() throws Exception {
createUser();
- userSessionRule.login("polop");
+ userSessionRule.logIn("polop");
tester.newPostRequest("api/users", "change_password")
.setParam("login", "john")
.execute();
session.clearCache();
String originalPassword = dbClient.userDao().selectOrFailByLogin(session, "john").getCryptedPassword();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
tester.newPostRequest("api/users", "change_password")
.setParam("login", "john")
.setParam("previousPassword", "Valar Dohaeris")
createUser();
session.clearCache();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
tester.newPostRequest("api/users", "change_password")
.setParam("login", "john")
.setParam("password", "Valar Morghulis")
createUser();
session.clearCache();
- userSessionRule.login("john");
+ userSessionRule.logIn("john");
tester.newPostRequest("api/users", "change_password")
.setParam("login", "john")
.setParam("previousPassword", "I dunno")
@Test
public void reactivate_user() throws Exception {
- userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.users().insertUser(newUserDto("john", "John", "john@email.com"));
db.getDbClient().userDao().deactivateUserByLogin(db.getSession(), "john");
@Test(expected = ForbiddenException.class)
public void fail_on_missing_permission() throws Exception {
- userSessionRule.login("not_admin");
+ userSessionRule.logIn("not_admin");
tester.newPostRequest("api/users", "create")
.setParam("login", "john")
}
private void authenticateAsAdmin() {
- userSessionRule.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSessionRule.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
private void executeRequest(String login) throws Exception {
@Test
public void json_example() throws Exception {
- userSessionRule.login("obiwan.kenobi").setName("Obiwan Kenobi")
+ userSessionRule.logIn("obiwan.kenobi").setName("Obiwan Kenobi")
.setGlobalPermissions(GlobalPermissions.ALL.toArray(new String[0]));
UserDto obiwan = db.users().insertUser(
newUserDto("obiwan.kenobi", "Obiwan Kenobi", "obiwan.kenobi@starwars.com")
@Test
public void cannot_deactivate_self() throws Exception {
UserDto user = createUser();
- userSession.login(user.getLogin()).setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn(user.getLogin()).setGlobalPermissions(SYSTEM_ADMIN);
expectedException.expect(BadRequestException.class);
expectedException.expectMessage("Self-deactivation is not possible");
@Test
public void deactivation_requires_administrator_permission() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
}
private void loginAsAdmin() {
- userSession.login("admin").setGlobalPermissions(SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(SYSTEM_ADMIN);
}
private TestResponse deactivate(String login) {
session.commit();
tester = new WsTester(new UsersWs(new GroupsAction(dbClient, userSession)));
- userSession.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
@After
@Test(expected = ForbiddenException.class)
public void fail_on_missing_permission() throws Exception {
- userSession.login("not-admin");
+ userSession.logIn("not-admin");
tester.newGetRequest("api/users", "groups")
.setParam("login", "john").execute();
}
}
private void loginAsAdmin() {
- userSession.login("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn("admin").setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
}
private void loginAsSimpleUser() {
- userSession.login("user");
+ userSession.logIn("user");
}
}
@Rule
public EsTester esTester = new EsTester(new UserIndexDefinition(settings));
@Rule
- public UserSessionRule userSessionRule = UserSessionRule.standalone().login("admin")
+ public UserSessionRule userSessionRule = UserSessionRule.standalone().logIn("admin")
.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
private DbClient dbClient = dbTester.getDbClient();
public void fail_on_missing_permission() throws Exception {
createUser();
- userSessionRule.login("polop");
+ userSessionRule.logIn("polop");
tester.newPostRequest("api/users", "update")
.setParam("login", "john")
.execute();
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login().addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), SYSTEM_ADMIN);
}
private GroupWsSupport newGroupWsSupport() {
@Test
public void fail_if_not_administrator() throws Exception {
- userSession.login("not-admin");
+ userSession.logIn("not-admin");
expectedException.expect(ForbiddenException.class);
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
private GroupWsSupport newGroupWsSupport() {
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
private WsTester.TestRequest newRequest() {
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login("admin").addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn("admin").addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
private void verifyUnchanged(UserDto user) {
}
private void loginAsDefaultOrgAdmin() {
- userSession.login("user").addOrganizationPermission(db.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
+ userSession.logIn("user").addOrganizationPermission(db.getDefaultOrganization().getUuid(), SYSTEM_ADMIN);
}
private GroupWsSupport newGroupWsSupport() {
@Test
public void require_admin_permission_on_organization() throws Exception {
GroupDto group = db.users().insertGroup();
- userSession.login("not-admin");
+ userSession.logIn("not-admin");
expectedException.expect(ForbiddenException.class);
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
}
@Test
public void fail_if_not_admin_of_organization() throws Exception {
GroupDto group = db.users().insertGroup();
- userSession.login("not-admin");
+ userSession.logIn("not-admin");
expectedException.expect(ForbiddenException.class);
}
private void loginAsAdmin(OrganizationDto org) {
- userSession.login().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().addOrganizationPermission(org.getUuid(), GlobalPermissions.SYSTEM_ADMIN);
}
}
when(tokenGenerator.generate()).thenReturn("123456789");
when(tokenGenerator.hash(anyString())).thenReturn("987654321");
userSession
- .login()
+ .logIn()
.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.users().insertUser(newUserDto().setLogin(GRACE_HOPPER));
db.users().insertUser(newUserDto().setLogin(ADA_LOVELACE));
@Test
public void a_user_can_generate_token_for_himself() {
- userSession.login(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
GenerateWsResponse response = newRequest(null, TOKEN_NAME);
@Test
public void fail_if_insufficient_privileges() {
- userSession.login(ADA_LOVELACE).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn(ADA_LOVELACE).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
newRequest(GRACE_HOPPER, TOKEN_NAME);
@Before
public void setUp() {
userSession
- .login()
+ .logIn()
.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
ws = new WsActionTester(
@Test
public void user_can_delete_its_own_tokens() {
- userSession.login(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
insertUserToken(newUserToken().setLogin(GRACE_HOPPER).setName("token-to-delete"));
String response = newRequest(null, "token-to-delete");
@Test
public void fail_if_insufficient_privileges() {
- userSession.login().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
insertUserToken(newUserToken().setLogin(GRACE_HOPPER).setName(TOKEN_NAME));
expectedException.expect(ForbiddenException.class);
@Before
public void setUp() {
- userSession.login().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
db.users().insertUser(newUserDto().setLogin(GRACE_HOPPER));
db.users().insertUser(newUserDto().setLogin(ADA_LOVELACE));
}
@Test
public void a_user_can_search_its_own_token() {
- userSession.login(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn(GRACE_HOPPER).setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
dbClient.userTokenDao().insert(dbSession, newUserToken()
.setCreatedAt(1448523067221L)
.setName("Project scan on Travis")
@Test
public void fail_when_insufficient_privileges() {
- userSession.login().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
+ userSession.logIn().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION);
expectedException.expect(ForbiddenException.class);
newRequest(GRACE_HOPPER);
@Test
public void search_by_component_and_return_no_records() throws Exception {
- userSession.login().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
+ userSession.logIn().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
Webhooks.DeliveriesWsResponse response = Webhooks.DeliveriesWsResponse.parseFrom(ws.newRequest()
.setMediaType(MediaTypes.PROTOBUF)
@Test
public void search_by_task_and_return_no_records() throws Exception {
- userSession.login().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
+ userSession.logIn().addProjectUuidPermissions(project.uuid(), UserRole.ADMIN);
Webhooks.DeliveriesWsResponse response = Webhooks.DeliveriesWsResponse.parseFrom(ws.newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.setHttpStatus(200);
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
String json = ws.newRequest()
.setParam("componentKey", project.getKey())
dbClient.webhookDeliveryDao().insert(db.getSession(), dto2);
dbClient.webhookDeliveryDao().insert(db.getSession(), dto3);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
Webhooks.DeliveriesWsResponse response = Webhooks.DeliveriesWsResponse.parseFrom(ws.newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.setComponentUuid(project.uuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
.setComponentUuid(project.uuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");
@Test
public void throw_IAE_if_both_component_and_task_parameters_are_set() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Either parameter 'ceTaskId' or 'componentKey' must be defined");
@Test
public void return_404_if_delivery_does_not_exist() throws Exception {
- userSession.login();
+ userSession.logIn();
expectedException.expect(NotFoundException.class);
.setPayload("{\"status\"=\"SUCCESS\"}");
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
String json = ws.newRequest()
.setParam("deliveryId", dto.getUuid())
.setErrorStacktrace("IOException -> can not connect");
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.ADMIN, project.uuid());
Webhooks.DeliveryWsResponse response = Webhooks.DeliveryWsResponse.parseFrom(ws.newRequest()
.setMediaType(MediaTypes.PROTOBUF)
.setComponentUuid(project.uuid());
dbClient.webhookDeliveryDao().insert(db.getSession(), dto);
db.commit();
- userSession.login().addProjectUuidPermissions(UserRole.USER, project.uuid());
+ userSession.logIn().addProjectUuidPermissions(UserRole.USER, project.uuid());
expectedException.expect(ForbiddenException.class);
expectedException.expectMessage("Insufficient privileges");