for UTs using ComponentTesting and/or ComponentDbTestertags/6.3-RC1
@@ -70,7 +70,7 @@ public class CeQueueImplTest { | |||
@Test | |||
public void submit_populates_component_name_and_key_of_CeTask_if_component_exists() { | |||
ComponentDto componentDto = insertComponent(ComponentTesting.newProjectDto("PROJECT_1")); | |||
ComponentDto componentDto = insertComponent(ComponentTesting.newProjectDto(dbTester.organizations().insert(), "PROJECT_1")); | |||
CeTaskSubmit taskSubmit = createTaskSubmit(CeTaskTypes.REPORT, componentDto.uuid(), null); | |||
CeTask task = underTest.submit(taskSubmit); |
@@ -33,6 +33,7 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.scanner.protocol.Constants.Severity; | |||
import org.sonar.scanner.protocol.input.ScannerInput.ServerIssue; | |||
import org.sonar.server.component.ComponentFinder; | |||
@@ -93,7 +94,7 @@ public class IssuesActionTest { | |||
@Test | |||
public void return_minimal_fields() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY); | |||
ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath(null); | |||
db.getDbClient().componentDao().insert(db.getSession(), project, module, file); | |||
@@ -131,7 +132,8 @@ public class IssuesActionTest { | |||
@Test | |||
public void issues_from_project() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY); | |||
ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"); | |||
db.getDbClient().componentDao().insert(db.getSession(), project, module, file); | |||
@@ -169,7 +171,7 @@ public class IssuesActionTest { | |||
@Test | |||
public void issues_from_module() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY); | |||
ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"); | |||
db.getDbClient().componentDao().insert(db.getSession(), project, module, file); | |||
@@ -207,7 +209,7 @@ public class IssuesActionTest { | |||
@Test | |||
public void issues_from_file() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY); | |||
ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java"); | |||
db.getDbClient().componentDao().insert(db.getSession(), project, module, file); | |||
@@ -245,7 +247,8 @@ public class IssuesActionTest { | |||
@Test | |||
public void issues_attached_on_module() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY); | |||
db.getDbClient().componentDao().insert(db.getSession(), project, module); | |||
db.getSession().commit(); | |||
@@ -282,7 +285,7 @@ public class IssuesActionTest { | |||
@Test | |||
public void project_issues_attached_file_on_removed_module() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), PROJECT_UUID).setKey(PROJECT_KEY); | |||
// File and module are removed | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project).setKey(MODULE_KEY).setEnabled(false); | |||
ComponentDto file = ComponentTesting.newFileDto(module, null, FILE_UUID).setKey(FILE_KEY).setPath("src/org/struts/Action.java").setEnabled(false); |
@@ -34,6 +34,8 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.db.qualityprofile.QualityProfileDto; | |||
import org.sonar.db.source.FileSourceDao; | |||
@@ -64,13 +66,15 @@ public class ProjectDataLoaderMediumTest { | |||
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester); | |||
DbSession dbSession; | |||
DbClient dbClient; | |||
ProjectDataLoader underTest; | |||
@Before | |||
public void before() { | |||
tester.clearDbAndIndexes(); | |||
dbSession = tester.get(DbClient.class).openSession(false); | |||
dbClient = tester.get(DbClient.class); | |||
dbSession = dbClient.openSession(false); | |||
underTest = tester.get(ProjectDataLoader.class); | |||
} | |||
@@ -81,15 +85,17 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_settings_with_global_scan_permission() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbSession.commit(); | |||
@@ -103,15 +109,17 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_settings_with_project_scan_permission() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").addProjectUuidPermissions(SCAN_EXECUTION, project.projectUuid()); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbSession.commit(); | |||
@@ -125,15 +133,17 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void not_returned_secured_settings_when_lgged_but_no_scan_permission() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbSession.commit(); | |||
@@ -145,24 +155,26 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_with_module_settings() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// Module properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId())); | |||
dbSession.commit(); | |||
@@ -179,19 +191,21 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_with_module_settings_inherited_from_project() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// No property on module -> should have the same as project | |||
@@ -208,31 +222,33 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_with_module_with_sub_module() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// Module properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module.getId())); | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, subModule); | |||
dbClient.componentDao().insert(dbSession, subModule); | |||
// Sub module properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty( | |||
dbClient.propertiesDao().saveProperty( | |||
dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER-DAO").setResourceId(subModule.getId())); | |||
dbSession.commit(); | |||
@@ -253,30 +269,32 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_project_with_two_modules() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
ComponentDto module1 = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module1); | |||
dbClient.componentDao().insert(dbSession, module1); | |||
// Module 1 properties | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module1.getId())); | |||
// This property should not be found on the other module | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(module1.getId())); | |||
ComponentDto module2 = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module2); | |||
dbClient.componentDao().insert(dbSession, module2); | |||
// Module 2 property | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-APPLICATION").setResourceId(module2.getId())); | |||
dbSession.commit(); | |||
@@ -296,15 +314,17 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_provisioned_project_settings() { | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
// No snapshot attached on the project -> provisioned project | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbSession.commit(); | |||
@@ -316,23 +336,25 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_sub_module_settings() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// No project properties | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// No module properties | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, subModule); | |||
dbClient.componentDao().insert(dbSession, subModule); | |||
// Sub module properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(subModule.getId())); | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(subModule.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(subModule.getId())); | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId())); | |||
dbSession.commit(); | |||
@@ -348,25 +370,27 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_sub_module_settings_including_settings_from_parent_modules() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project property | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// Module property | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(module.getId())); | |||
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); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, subModule); | |||
dbClient.componentDao().insert(dbSession, subModule); | |||
// Sub module properties | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(subModule.getId())); | |||
dbSession.commit(); | |||
@@ -382,23 +406,25 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_sub_module_settings_only_inherited_from_project() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR").setResourceId(project.getId())); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// No module property | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, subModule); | |||
dbClient.componentDao().insert(dbSession, subModule); | |||
// No sub module property | |||
dbSession.commit(); | |||
@@ -414,24 +440,26 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_sub_module_settings_inherited_from_project_and_module() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// Project properties | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
tester.get(DbClient.class).propertiesDao() | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.login.secured").setValue("john").setResourceId(project.getId())); | |||
dbClient.propertiesDao() | |||
.saveProperty(dbSession, new PropertyDto().setKey("sonar.coverage.exclusions").setValue("**/*.java").setResourceId(project.getId())); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// Module property | |||
tester.get(DbClient.class).propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("sonar.jira.project.key").setValue("SONAR-SERVER").setResourceId(module.getId())); | |||
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); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, subModule); | |||
dbClient.componentDao().insert(dbSession, subModule); | |||
// No sub module property | |||
dbSession.commit(); | |||
@@ -449,8 +477,10 @@ public class ProjectDataLoaderMediumTest { | |||
public void fail_when_no_browse_permission_and_no_scan_permission() { | |||
userSessionRule.login("john").setGlobalPermissions(); | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
try { | |||
@@ -463,8 +493,10 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void fail_when_not_preview_and_only_browse_permission_without_scan_permission() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
userSessionRule.login("john").addProjectUuidPermissions(UserRole.USER, project.projectUuid()); | |||
@@ -477,8 +509,10 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void fail_when_preview_and_only_scan_permission_without_browse_permission() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
userSessionRule.login("john").addProjectUuidPermissions(GlobalPermissions.SCAN_EXECUTION, project.projectUuid()); | |||
@@ -490,13 +524,15 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_file_data_from_single_project() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null, "file"); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, file); | |||
dbClient.componentDao().insert(dbSession, file); | |||
tester.get(FileSourceDao.class).insert(newFileSourceDto(file).setSrcHash("123456")); | |||
dbSession.commit(); | |||
@@ -509,22 +545,24 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_file_data_from_multi_modules() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// File on project | |||
ComponentDto projectFile = ComponentTesting.newFileDto(project, null, "projectFile"); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, projectFile); | |||
dbClient.componentDao().insert(dbSession, projectFile); | |||
tester.get(FileSourceDao.class).insert(newFileSourceDto(projectFile).setSrcHash("123456")); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// File on module | |||
ComponentDto moduleFile = ComponentTesting.newFileDto(module, null, "moduleFile"); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, moduleFile); | |||
dbClient.componentDao().insert(dbSession, moduleFile); | |||
tester.get(FileSourceDao.class).insert(newFileSourceDto(moduleFile).setSrcHash("789456")); | |||
dbSession.commit(); | |||
@@ -536,22 +574,24 @@ public class ProjectDataLoaderMediumTest { | |||
@Test | |||
public void return_file_data_from_module() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, project); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
dbClient.organizationDao().insert(dbSession, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(dbSession, project); | |||
addDefaultProfile(); | |||
// File on project | |||
ComponentDto projectFile = ComponentTesting.newFileDto(project, null, "projectFile"); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, projectFile); | |||
dbClient.componentDao().insert(dbSession, projectFile); | |||
tester.get(FileSourceDao.class).insert(newFileSourceDto(projectFile).setSrcHash("123456").setRevision("987654321")); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
userSessionRule.login("john").setGlobalPermissions(SCAN_EXECUTION); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, module); | |||
dbClient.componentDao().insert(dbSession, module); | |||
// File on module | |||
ComponentDto moduleFile = ComponentTesting.newFileDto(module, null, "moduleFile"); | |||
tester.get(DbClient.class).componentDao().insert(dbSession, moduleFile); | |||
dbClient.componentDao().insert(dbSession, moduleFile); | |||
tester.get(FileSourceDao.class).insert(newFileSourceDto(moduleFile).setSrcHash("789456").setRevision("123456789")); | |||
dbSession.commit(); | |||
@@ -565,7 +605,7 @@ public class ProjectDataLoaderMediumTest { | |||
private void addDefaultProfile() { | |||
QualityProfileDto profileDto = newQProfileDto(QProfileName.createFor(ServerTester.Xoo.KEY, "SonarQube way"), "abcd").setRulesUpdatedAt( | |||
formatDateTime(new Date())).setDefault(true); | |||
tester.get(DbClient.class).qualityProfileDao().insert(dbSession, profileDto); | |||
dbClient.qualityProfileDao().insert(dbSession, profileDto); | |||
} | |||
private static FileSourceDto newFileSourceDto(ComponentDto file) { |
@@ -39,6 +39,7 @@ import org.sonar.db.ce.CeQueueDto; | |||
import org.sonar.db.ce.CeTaskTypes; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.TestRequest; | |||
@@ -204,9 +205,10 @@ public class ActivityActionTest { | |||
@Test | |||
public void search_activity_by_component_name() throws IOException { | |||
ComponentDto struts = newProjectDto().setName("old apache struts").setUuid("P1").setProjectUuid("P1"); | |||
ComponentDto zookeeper = newProjectDto().setName("new apache zookeeper").setUuid("P2").setProjectUuid("P2"); | |||
ComponentDto eclipse = newProjectDto().setName("eclipse").setUuid("P3").setProjectUuid("P3"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto struts = newProjectDto(organizationDto).setName("old apache struts").setUuid("P1").setProjectUuid("P1"); | |||
ComponentDto zookeeper = newProjectDto(organizationDto).setName("new apache zookeeper").setUuid("P2").setProjectUuid("P2"); | |||
ComponentDto eclipse = newProjectDto(organizationDto).setName("eclipse").setUuid("P3").setProjectUuid("P3"); | |||
componentDb.insertProjectAndSnapshot(struts); | |||
componentDb.insertProjectAndSnapshot(zookeeper); | |||
componentDb.insertProjectAndSnapshot(eclipse); | |||
@@ -224,8 +226,9 @@ public class ActivityActionTest { | |||
@Test | |||
public void search_activity_returns_views_and_developers() { | |||
ComponentDto apacheView = newView().setName("Apache View").setUuid("V1").setProjectUuid("V1"); | |||
ComponentDto developer = newDeveloper("Apache Developer").setUuid("D1").setProjectUuid("D1"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto apacheView = newView(organizationDto).setName("Apache View").setUuid("V1").setProjectUuid("V1"); | |||
ComponentDto developer = newDeveloper(organizationDto, "Apache Developer").setUuid("D1").setProjectUuid("D1"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
componentDb.insertViewAndSnapshot(apacheView); | |||
componentDb.indexComponents(developer.uuid(), apacheView.uuid()); |
@@ -38,6 +38,7 @@ import org.sonar.db.ce.CeActivityDto; | |||
import org.sonar.db.ce.CeQueueDto; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -92,8 +93,9 @@ public class ActivityStatusActionTest { | |||
String projectUuid = "project-uuid"; | |||
String anotherProjectUuid = "another-project-uuid"; | |||
userSession.login().addProjectUuidPermissions(UserRole.ADMIN, projectUuid); | |||
componentDb.insertComponent(newProjectDto(projectUuid)); | |||
componentDb.insertComponent(newProjectDto(anotherProjectUuid)); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
componentDb.insertComponent(newProjectDto(organizationDto, projectUuid)); | |||
componentDb.insertComponent(newProjectDto(organizationDto, anotherProjectUuid)); | |||
// pending tasks returned | |||
insertInQueue(CeQueueDto.Status.PENDING, projectUuid); | |||
insertInQueue(CeQueueDto.Status.PENDING, projectUuid); | |||
@@ -124,7 +126,7 @@ public class ActivityStatusActionTest { | |||
@Test | |||
public void fail_if_component_uuid_and_key_are_provided() { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
componentDb.insertComponent(project); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -64,7 +64,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void empty_queue_and_empty_activity() { | |||
componentDbTester.insertComponent(newProjectDto("PROJECT_1")); | |||
componentDbTester.insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1")); | |||
userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); | |||
TestResponse wsResponse = ws.newRequest() | |||
@@ -79,7 +79,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void project_tasks() { | |||
componentDbTester.insertComponent(newProjectDto("PROJECT_1")); | |||
componentDbTester.insertComponent(newProjectDto(dbTester.organizations().insert(), "PROJECT_1")); | |||
userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); | |||
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); | |||
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); | |||
@@ -118,7 +118,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void canceled_tasks_must_not_be_picked_as_current_analysis() { | |||
componentDbTester.insertComponent(newProjectDto("PROJECT_1")); | |||
componentDbTester.insertComponent(newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1")); | |||
userSession.addComponentUuidPermission(UserRole.USER, "PROJECT_1", "PROJECT_1"); | |||
insertActivity("T1", "PROJECT_1", CeActivityDto.Status.SUCCESS); | |||
insertActivity("T2", "PROJECT_2", CeActivityDto.Status.FAILED); |
@@ -31,7 +31,6 @@ import org.sonar.db.ce.CeActivityDto; | |||
import org.sonar.db.ce.CeQueueDto; | |||
import org.sonar.db.ce.CeTaskTypes; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -49,10 +48,6 @@ import static org.sonarqube.ws.MediaTypes.PROTOBUF; | |||
public class TaskActionTest { | |||
static final ComponentDto PROJECT = ComponentTesting.newProjectDto() | |||
.setUuid("PROJECT_1") | |||
.setName("Project One") | |||
.setKey("P1"); | |||
private static final String SOME_TASK_UUID = "TASK_1"; | |||
@Rule | |||
@@ -64,13 +59,14 @@ public class TaskActionTest { | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); | |||
TaskAction underTest = new TaskAction(dbTester.getDbClient(), formatter, userSession); | |||
WsActionTester ws = new WsActionTester(underTest); | |||
private ComponentDto project; | |||
private TaskFormatter formatter = new TaskFormatter(dbTester.getDbClient(), System2.INSTANCE); | |||
private TaskAction underTest = new TaskAction(dbTester.getDbClient(), formatter, userSession); | |||
private WsActionTester ws = new WsActionTester(underTest); | |||
@Before | |||
public void setUp() { | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), PROJECT); | |||
project = dbTester.components().insertProject(dbTester.organizations().insert()); | |||
} | |||
@Test | |||
@@ -80,7 +76,7 @@ public class TaskActionTest { | |||
CeQueueDto queueDto = new CeQueueDto(); | |||
queueDto.setTaskType(CeTaskTypes.REPORT); | |||
queueDto.setUuid(SOME_TASK_UUID); | |||
queueDto.setComponentUuid(PROJECT.uuid()); | |||
queueDto.setComponentUuid(project.uuid()); | |||
queueDto.setStatus(CeQueueDto.Status.PENDING); | |||
queueDto.setSubmitterLogin("john"); | |||
persist(queueDto); | |||
@@ -94,9 +90,9 @@ public class TaskActionTest { | |||
assertThat(taskResponse.getTask().getId()).isEqualTo(SOME_TASK_UUID); | |||
assertThat(taskResponse.getTask().getStatus()).isEqualTo(WsCe.TaskStatus.PENDING); | |||
assertThat(taskResponse.getTask().getSubmitterLogin()).isEqualTo("john"); | |||
assertThat(taskResponse.getTask().getComponentId()).isEqualTo(PROJECT.uuid()); | |||
assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(PROJECT.key()); | |||
assertThat(taskResponse.getTask().getComponentName()).isEqualTo(PROJECT.name()); | |||
assertThat(taskResponse.getTask().getComponentId()).isEqualTo(project.uuid()); | |||
assertThat(taskResponse.getTask().getComponentKey()).isEqualTo(project.key()); | |||
assertThat(taskResponse.getTask().getComponentName()).isEqualTo(project.name()); | |||
assertThat(taskResponse.getTask().hasExecutionTimeMs()).isFalse(); | |||
assertThat(taskResponse.getTask().getLogs()).isFalse(); | |||
} | |||
@@ -117,9 +113,9 @@ public class TaskActionTest { | |||
WsCe.Task task = taskResponse.getTask(); | |||
assertThat(task.getId()).isEqualTo(SOME_TASK_UUID); | |||
assertThat(task.getStatus()).isEqualTo(WsCe.TaskStatus.FAILED); | |||
assertThat(task.getComponentId()).isEqualTo(PROJECT.uuid()); | |||
assertThat(task.getComponentKey()).isEqualTo(PROJECT.key()); | |||
assertThat(task.getComponentName()).isEqualTo(PROJECT.name()); | |||
assertThat(task.getComponentId()).isEqualTo(project.uuid()); | |||
assertThat(task.getComponentKey()).isEqualTo(project.key()); | |||
assertThat(task.getComponentName()).isEqualTo(project.name()); | |||
assertThat(task.getAnalysisId()).isEqualTo(activityDto.getAnalysisUuid()); | |||
assertThat(task.getExecutionTimeMs()).isEqualTo(500L); | |||
assertThat(task.getLogs()).isFalse(); | |||
@@ -290,13 +286,13 @@ public class TaskActionTest { | |||
@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"); | |||
queueDto.setUuid(SOME_TASK_UUID); | |||
queueDto.setStatus(CeQueueDto.Status.PENDING); | |||
queueDto.setComponentUuid(PROJECT.uuid()); | |||
queueDto.setComponentUuid(project.uuid()); | |||
persist(queueDto); | |||
ws.newRequest() | |||
@@ -307,10 +303,10 @@ public class TaskActionTest { | |||
@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()); | |||
.setComponentUuid(project.uuid()); | |||
persist(activityDto); | |||
ws.newRequest() | |||
@@ -323,7 +319,7 @@ public class TaskActionTest { | |||
CeQueueDto queueDto = new CeQueueDto(); | |||
queueDto.setTaskType(CeTaskTypes.REPORT); | |||
queueDto.setUuid(uuid); | |||
queueDto.setComponentUuid(PROJECT.uuid()); | |||
queueDto.setComponentUuid(project.uuid()); | |||
CeActivityDto activityDto = new CeActivityDto(queueDto); | |||
activityDto.setStatus(CeActivityDto.Status.FAILED); | |||
activityDto.setExecutionTimeMs(500L); |
@@ -30,7 +30,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.ce.CeActivityDto; | |||
import org.sonar.db.ce.CeQueueDto; | |||
import org.sonar.db.ce.CeTaskTypes; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonarqube.ws.WsCe; | |||
import static java.util.Arrays.asList; | |||
@@ -76,8 +76,8 @@ public class TaskFormatterTest { | |||
@Test | |||
public void formatQueue_with_component_and_other_fields() throws IOException { | |||
String uuid = "COMPONENT_UUID"; | |||
db.getDbClient().componentDao().insert(db.getSession(), | |||
ComponentTesting.newProjectDto(uuid).setKey("COMPONENT_KEY").setName("Component Name")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
db.components().insertProject(organizationDto, (t) -> t.setUuid(uuid).setKey("COMPONENT_KEY").setName("Component Name")); | |||
CeQueueDto dto = new CeQueueDto(); | |||
dto.setUuid("UUID"); |
@@ -146,7 +146,7 @@ public class ComponentCleanerServiceTest { | |||
@Test | |||
public void fail_to_delete_not_project_scope() throws Exception { | |||
mockResourceTypeAsValidProject(); | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, project); | |||
ComponentDto file = newFileDto(project, null); | |||
dbClient.componentDao().insert(dbSession, file); | |||
@@ -161,7 +161,7 @@ public class ComponentCleanerServiceTest { | |||
ResourceType resourceType = mock(ResourceType.class); | |||
when(resourceType.getBooleanProperty("deletable")).thenReturn(false); | |||
when(mockResourceTypes.get(anyString())).thenReturn(resourceType); | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
@@ -172,7 +172,7 @@ public class ComponentCleanerServiceTest { | |||
@Test | |||
public void fail_to_delete_null_resource_type() throws Exception { | |||
when(mockResourceTypes.get(anyString())).thenReturn(null); | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
@@ -182,7 +182,7 @@ public class ComponentCleanerServiceTest { | |||
private DbData insertDataInDb(int id) { | |||
String suffix = String.valueOf(id); | |||
ComponentDto project = newProjectDto("project-uuid-" + suffix) | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid-" + suffix) | |||
.setKey("project-key-" + suffix); | |||
RuleDto rule = RuleTesting.newDto(RuleKey.of("sonarqube", "rule-" + suffix)); | |||
dbClient.ruleDao().insert(dbSession, rule); | |||
@@ -219,7 +219,7 @@ public class ComponentCleanerServiceTest { | |||
mockResourceTypeAsValidProject(); | |||
String suffix = String.valueOf(id); | |||
ComponentDto project = newProjectDto("project-uuid-" + suffix) | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid-" + suffix) | |||
.setKey("project-key-" + suffix); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); |
@@ -137,7 +137,7 @@ public class ComponentFinderTest { | |||
@Test | |||
public void get_component_by_uuid() { | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
ComponentDto component = underTest.getByUuidOrKey(dbSession, "project-uuid", null, ID_AND_KEY); | |||
@@ -146,7 +146,7 @@ public class ComponentFinderTest { | |||
@Test | |||
public void get_component_by_key() { | |||
componentDb.insertComponent(newProjectDto().setKey("project-key")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key")); | |||
ComponentDto component = underTest.getByUuidOrKey(dbSession, null, "project-key", ID_AND_KEY); | |||
@@ -155,7 +155,7 @@ public class ComponentFinderTest { | |||
@Test | |||
public void getByIdOrKey_get_component_by_id() { | |||
ComponentDto source = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto source = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
ComponentDto component = underTest.getByIdOrKey(dbSession, source.getId(), null, ID_AND_KEY); | |||
@@ -164,7 +164,7 @@ public class ComponentFinderTest { | |||
@Test | |||
public void getByIdOrKey_get_component_by_key() { | |||
componentDb.insertComponent(newProjectDto().setKey("project-key")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key")); | |||
ComponentDto component = underTest.getByIdOrKey(dbSession, null, "project-key", ID_AND_KEY); | |||
@@ -37,6 +37,7 @@ import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.ResourceIndexDao; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.es.ProjectMeasuresIndexDefinition; | |||
import org.sonar.server.component.es.ProjectMeasuresIndexer; | |||
import org.sonar.server.es.EsTester; | |||
@@ -270,7 +271,7 @@ public class ComponentServiceTest { | |||
expectedException.expectMessage("Could not create Project, key already exists: struts"); | |||
userSession.login("john").setGlobalPermissions(PROVISIONING); | |||
ComponentDto project = ComponentTesting.newProjectDto().setKey("struts"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey("struts"); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
@@ -304,10 +305,11 @@ public class ComponentServiceTest { | |||
return null; | |||
}).when(componentDao).insert(eq(session), any(ComponentDto.class)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
when(componentDao.selectComponentsHavingSameKeyOrderedById(session, projectKey)).thenReturn(newArrayList( | |||
ComponentTesting.newProjectDto().setId(1L).setKey(projectKey), | |||
ComponentTesting.newProjectDto().setId(2L).setKey(projectKey), | |||
ComponentTesting.newProjectDto().setId(3L).setKey(projectKey))); | |||
ComponentTesting.newProjectDto(organizationDto).setId(1L).setKey(projectKey), | |||
ComponentTesting.newProjectDto(organizationDto).setId(2L).setKey(projectKey), | |||
ComponentTesting.newProjectDto(organizationDto).setId(3L).setKey(projectKey))); | |||
underTest = new ComponentService(dbClient, i18n, userSession, System2.INSTANCE, new ComponentFinder(dbClient), projectMeasuresIndexer); | |||
underTest.create( | |||
@@ -361,7 +363,7 @@ public class ComponentServiceTest { | |||
@Test | |||
public void bulk_update() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto().setKey("my_project")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(dbTester.organizations().insert()).setKey("my_project")); | |||
ComponentDto module = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:module")); | |||
ComponentDto inactiveModule = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:inactive_module").setEnabled(false)); | |||
ComponentDto file = componentDb.insertComponent(newFileDto(module, null).setKey("my_project:root:module:src/File.xoo")); | |||
@@ -386,7 +388,7 @@ public class ComponentServiceTest { | |||
} | |||
private ComponentDto insertSampleProject() { | |||
return componentDb.insertComponent(newProjectDto().setKey("sample:root")); | |||
return componentDb.insertComponent(newProjectDto(dbTester.organizations().insert()).setKey("sample:root")); | |||
} | |||
private void assertProjectIsInIndex(String uuid) { |
@@ -199,7 +199,7 @@ public class ComponentServiceUpdateKeyTest { | |||
@Test | |||
public void bulk_update_key() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto().setKey("my_project")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey("my_project")); | |||
ComponentDto module = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:module")); | |||
ComponentDto inactiveModule = componentDb.insertComponent(newModuleDto(project).setKey("my_project:root:inactive_module").setEnabled(false)); | |||
ComponentDto file = componentDb.insertComponent(newFileDto(module, null).setKey("my_project:root:module:src/File.xoo")); | |||
@@ -234,7 +234,7 @@ public class ComponentServiceUpdateKeyTest { | |||
} | |||
private ComponentDto insertProject(String key) { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto().setKey(key)); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey(key)); | |||
projectMeasuresIndexer.index(project.uuid()); | |||
return project; | |||
} |
@@ -30,6 +30,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.permission.index.PermissionIndexerTester; | |||
@@ -67,9 +68,10 @@ public class ProjectMeasuresIndexerTest { | |||
@Test | |||
public void index_all_project() { | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto()); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto()); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto()); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto)); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto)); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto)); | |||
underTest.index(); | |||
@@ -87,9 +89,10 @@ public class ProjectMeasuresIndexerTest { | |||
@Test | |||
public void index_one_project() throws Exception { | |||
ComponentDto project = newProjectDto(); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = newProjectDto(organizationDto); | |||
componentDbTester.insertProjectAndSnapshot(project); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto()); | |||
componentDbTester.insertProjectAndSnapshot(newProjectDto(organizationDto)); | |||
underTest.index(project.uuid()); | |||
@@ -104,7 +107,7 @@ public class ProjectMeasuresIndexerTest { | |||
.setKey("Old Key") | |||
.setName("Old Name") | |||
.setAnalysedAt(new Date(1_000_000L))); | |||
ComponentDto project = newProjectDto(uuid).setKey("New key").setName("New name"); | |||
ComponentDto project = newProjectDto(dbTester.getDefaultOrganization(), uuid).setKey("New key").setName("New name"); | |||
SnapshotDto analysis = componentDbTester.insertProjectAndSnapshot(project); | |||
underTest.index(project.uuid()); | |||
@@ -124,11 +127,12 @@ public class ProjectMeasuresIndexerTest { | |||
@Test | |||
public void delete_project() { | |||
ComponentDto project1 = newProjectDto(); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project1 = newProjectDto(organizationDto); | |||
componentDbTester.insertProjectAndSnapshot(project1); | |||
ComponentDto project2 = newProjectDto(); | |||
ComponentDto project2 = newProjectDto(organizationDto); | |||
componentDbTester.insertProjectAndSnapshot(project2); | |||
ComponentDto project3 = newProjectDto(); | |||
ComponentDto project3 = newProjectDto(organizationDto); | |||
componentDbTester.insertProjectAndSnapshot(project3); | |||
underTest.index(); | |||
authorizationIndexerTester.indexProjectPermission(project1.uuid(), emptyList(), emptyList()); | |||
@@ -143,7 +147,7 @@ public class ProjectMeasuresIndexerTest { | |||
@Test | |||
public void does_nothing_when_deleting_unknown_project() throws Exception { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(dbTester.organizations().insert()); | |||
componentDbTester.insertProjectAndSnapshot(project); | |||
underTest.index(); | |||
authorizationIndexerTester.indexProjectPermission(project.uuid(), emptyList(), emptyList()); |
@@ -122,7 +122,7 @@ public class AppActionTest { | |||
} | |||
private void insertComponentsAndAnalysis() { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID) | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), PROJECT_UUID) | |||
.setLongName("SonarQube") | |||
.setKey(PROJECT_KEY); | |||
ComponentDto module = ComponentTesting.newModuleDto(MODULE_UUID, project) |
@@ -36,6 +36,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.component.ComponentService; | |||
import org.sonar.server.component.es.ProjectMeasuresIndexDefinition; | |||
@@ -97,9 +98,10 @@ public class BulkUpdateKeyActionTest { | |||
@Test | |||
public void json_example() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto().setKey("my_project")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(organizationDto).setKey("my_project")); | |||
componentDb.insertComponent(newModuleDto(project).setKey("my_project:module_1")); | |||
ComponentDto anotherProject = componentDb.insertComponent(newProjectDto().setKey("another_project")); | |||
ComponentDto anotherProject = componentDb.insertComponent(newProjectDto(organizationDto).setKey("another_project")); | |||
componentDb.insertComponent(newModuleDto(anotherProject).setKey("my_new_project:module_1")); | |||
ComponentDto module2 = componentDb.insertComponent(newModuleDto(project).setKey("my_project:module_2")); | |||
componentDb.insertComponent(newFileDto(module2, null)); | |||
@@ -151,7 +153,7 @@ public class BulkUpdateKeyActionTest { | |||
public void bulk_update_provisioned_project_key() { | |||
String oldKey = "provisionedProject"; | |||
String newKey = "provisionedProject2"; | |||
ComponentDto provisionedProject = componentDb.insertComponent(newProjectDto().setKey(oldKey)); | |||
ComponentDto provisionedProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey(oldKey)); | |||
callByKey(provisionedProject.key(), oldKey, newKey); | |||
@@ -160,8 +162,8 @@ public class BulkUpdateKeyActionTest { | |||
@Test | |||
public void fail_to_bulk_if_a_component_already_exists_with_the_same_key() { | |||
componentDb.insertComponent(newProjectDto().setKey("my_project")); | |||
componentDb.insertComponent(newProjectDto().setKey("your_project")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("my_project")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("your_project")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Impossible to update key: a component with key \"your_project\" already exists."); | |||
@@ -274,7 +276,7 @@ public class BulkUpdateKeyActionTest { | |||
} | |||
private ComponentDto insertMyProject() { | |||
return componentDb.insertComponent(newProjectDto().setKey(MY_PROJECT_KEY)); | |||
return componentDb.insertComponent(newProjectDto(db.organizations().insert()).setKey(MY_PROJECT_KEY)); | |||
} | |||
private WsComponents.BulkUpdateKeyWsResponse callDryRunByUuid(@Nullable String uuid, @Nullable String from, @Nullable String to) { |
@@ -36,6 +36,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ResourceTypesRule; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.UnauthorizedException; | |||
import org.sonar.server.i18n.I18nRule; | |||
@@ -83,9 +84,10 @@ public class SearchActionTest { | |||
@Test | |||
public void search_json_example() { | |||
componentDb.insertComponent(newView()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
componentDb.insertComponent(newView(organizationDto)); | |||
ComponentDto project = componentDb.insertComponent( | |||
newProjectDto("project-uuid") | |||
newProjectDto(organizationDto, "project-uuid") | |||
.setName("Project Name") | |||
.setKey("project-key")); | |||
ComponentDto module = componentDb.insertComponent( | |||
@@ -114,9 +116,10 @@ public class SearchActionTest { | |||
@Test | |||
public void search_with_pagination() throws IOException { | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
for (int i = 1; i <= 9; i++) { | |||
componentDb.insertComponent( | |||
newProjectDto("project-uuid-" + i) | |||
newProjectDto(organizationDto, "project-uuid-" + i) | |||
.setName("Project Name " + i)); | |||
} | |||
db.commit(); | |||
@@ -134,8 +137,8 @@ public class SearchActionTest { | |||
@Test | |||
public void search_with_key_query() throws IOException { | |||
componentDb.insertComponent(newProjectDto().setKey("project-_%-key")); | |||
componentDb.insertComponent(newProjectDto().setKey("project-key-without-escaped-characters")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-_%-key")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("project-key-without-escaped-characters")); | |||
db.commit(); | |||
InputStream responseStream = newRequest(Qualifiers.PROJECT) | |||
@@ -149,8 +152,9 @@ public class SearchActionTest { | |||
@Test | |||
public void search_with_language() throws IOException { | |||
componentDb.insertComponent(newProjectDto().setKey("java-project").setLanguage("java")); | |||
componentDb.insertComponent(newProjectDto().setKey("cpp-project").setLanguage("cpp")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
componentDb.insertComponent(newProjectDto(organizationDto).setKey("java-project").setLanguage("java")); | |||
componentDb.insertComponent(newProjectDto(organizationDto).setKey("cpp-project").setLanguage("cpp")); | |||
db.commit(); | |||
InputStream responseStream = newRequest(Qualifiers.PROJECT) |
@@ -172,7 +172,7 @@ public class SearchProjectsActionTest { | |||
ComponentDto project = newProjectDto(organizationDto).setName("SonarQube"); | |||
ComponentDto directory = newDirectory(project, "path"); | |||
insertProjectInDbAndEs(project); | |||
componentDb.insertComponents(newModuleDto(project), newView(), newDeveloper("Sonar Developer"), directory, newFileDto(project, directory)); | |||
componentDb.insertComponents(newModuleDto(project), newView(organizationDto), newDeveloper(organizationDto, "Sonar Developer"), directory, newFileDto(project, directory)); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -199,7 +199,7 @@ public class SearchProjectsActionTest { | |||
public void filter_projects_on_favorites() { | |||
long javaId = insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization(), "java-id").setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d))); | |||
long markDownId = insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization(), "markdown-id").setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d))); | |||
insertProjectInDbAndEs(newProjectDto(db.organizations().insert()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d))); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(javaId).setUserId(Long.valueOf(userSession.getUserId()))); | |||
dbClient.propertiesDao().saveProperty(dbSession, new PropertyDto().setKey("favourite").setResourceId(markDownId).setUserId(Long.valueOf(userSession.getUserId()))); | |||
dbSession.commit(); |
@@ -79,7 +79,7 @@ public class ShowActionTest { | |||
@Test | |||
public void show_by_key_with_project_permission() { | |||
userSession.anonymous().login().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid").setKey("project-key")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key")); | |||
ShowWsResponse response = newRequest(null, "project-key"); | |||
@@ -90,7 +90,7 @@ public class ShowActionTest { | |||
@Test | |||
public void show_with_browse_permission() { | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.USER, "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
ShowWsResponse response = newRequest("project-uuid", null); | |||
@@ -99,7 +99,7 @@ public class ShowActionTest { | |||
@Test | |||
public void show_provided_project() { | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
ShowWsResponse response = newRequest("project-uuid", null); | |||
@@ -110,7 +110,7 @@ public class ShowActionTest { | |||
public void fail_if_not_enough_privilege() { | |||
userSession.anonymous().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); | |||
expectedException.expect(ForbiddenException.class); | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
newRequest("project-uuid", null); | |||
} |
@@ -110,7 +110,7 @@ public class TreeActionTest { | |||
@Test | |||
public void return_children() throws IOException { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto module = newModuleDto("module-uuid-1", project); | |||
componentDb.insertComponent(module); | |||
@@ -140,7 +140,7 @@ public class TreeActionTest { | |||
@Test | |||
public void return_descendants() throws IOException { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto module = newModuleDto("module-uuid-1", project); | |||
componentDb.insertComponent(module); | |||
@@ -170,7 +170,7 @@ public class TreeActionTest { | |||
@Test | |||
public void filter_descendants_by_qualifier() throws IOException { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
componentDb.insertComponent(newFileDto(project, 1)); | |||
componentDb.insertComponent(newFileDto(project, 2)); | |||
@@ -188,7 +188,7 @@ public class TreeActionTest { | |||
@Test | |||
public void return_leaves() throws IOException { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto module = newModuleDto("module-uuid-1", project); | |||
componentDb.insertComponent(module); | |||
@@ -212,7 +212,7 @@ public class TreeActionTest { | |||
@Test | |||
public void sort_descendants_by_qualifier() throws IOException { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
componentDb.insertComponent(newFileDto(project, 1)); | |||
componentDb.insertComponent(newFileDto(project, 2)); | |||
@@ -287,7 +287,7 @@ public class TreeActionTest { | |||
public void return_projects_composing_a_view() { | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto view = newView("view-uuid"); | |||
ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); | |||
componentDb.insertViewAndSnapshot(view); | |||
componentDb.insertComponent(newProjectCopy("project-copy-uuid", project, view)); | |||
@@ -304,7 +304,7 @@ public class TreeActionTest { | |||
expectedException.expect(ForbiddenException.class); | |||
userSession.anonymous().login() | |||
.addProjectUuidPermissions(UserRole.CODEVIEWER, "project-uuid"); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
db.commit(); | |||
ws.newRequest() | |||
@@ -316,7 +316,7 @@ public class TreeActionTest { | |||
public void fail_when_page_size_above_500() { | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("The 'ps' parameter must be less than 500"); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
db.commit(); | |||
ws.newRequest() | |||
@@ -329,7 +329,7 @@ public class TreeActionTest { | |||
public void fail_when_search_query_has_less_than_3_characters() { | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("The 'q' parameter must have at least 3 characters"); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
db.commit(); | |||
ws.newRequest() | |||
@@ -341,7 +341,7 @@ public class TreeActionTest { | |||
@Test | |||
public void fail_when_sort_is_unknown() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
db.commit(); | |||
ws.newRequest() | |||
@@ -353,7 +353,7 @@ public class TreeActionTest { | |||
@Test | |||
public void fail_when_strategy_is_unknown() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
db.commit(); | |||
ws.newRequest() | |||
@@ -401,7 +401,7 @@ public class TreeActionTest { | |||
} | |||
private ComponentDto initJsonExampleComponents() throws IOException { | |||
ComponentDto project = newProjectDto("MY_PROJECT_ID") | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "MY_PROJECT_ID") | |||
.setKey("MY_PROJECT_KEY") | |||
.setName("Project Name"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); |
@@ -129,7 +129,7 @@ public class UpdateKeyActionTest { | |||
} | |||
private ComponentDto insertProject() { | |||
return componentDb.insertComponent(newProjectDto()); | |||
return componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
} | |||
private String callByUuid(@Nullable String uuid, @Nullable String newKey) { |
@@ -76,7 +76,7 @@ public class SettingsRepositoryTest { | |||
@Test | |||
public void get_project_settings_from_db() { | |||
ComponentDto project = ComponentTesting.newProjectDto().setKey(ROOT.getKey()); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(ROOT.getKey()); | |||
dbClient.componentDao().insert(session, project); | |||
dbClient.propertiesDao().saveProperty(session, new PropertyDto().setResourceId(project.getId()).setKey("key").setValue("value")); | |||
session.commit(); |
@@ -276,7 +276,7 @@ public class IntegrateIssuesVisitorTest { | |||
} | |||
private void addBaseIssue(RuleKey ruleKey) { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project, file); | |||
@@ -33,6 +33,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderImpl; | |||
@@ -168,7 +169,8 @@ public class BuildComponentTreeStepTest { | |||
@Test | |||
public void return_existing_uuids() { | |||
ComponentDto project = insertComponent(newProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY)); | |||
ComponentDto module = insertComponent(newModuleDto("BCDE", project).setKey(REPORT_MODULE_KEY)); | |||
ComponentDto directory = newDirectory(module, "CDEF", REPORT_DIR_KEY_1); | |||
insertComponent(directory.setKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1)); | |||
@@ -247,7 +249,8 @@ public class BuildComponentTreeStepTest { | |||
@Test | |||
public void return_existing_uuids_when_components_were_removed() { | |||
ComponentDto project = insertComponent(newProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY)); | |||
ComponentDto removedModule = insertComponent(newModuleDto("BCDE", project).setKey(REPORT_MODULE_KEY).setEnabled(false)); | |||
ComponentDto removedDirectory = insertComponent(newDirectory(removedModule, "CDEF", REPORT_DIR_KEY_1).setKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1).setEnabled(false)); | |||
insertComponent(newFileDto(removedModule, removedDirectory, "DEFG").setKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1).setEnabled(false)); | |||
@@ -277,7 +280,8 @@ public class BuildComponentTreeStepTest { | |||
@Test | |||
public void set_no_base_project_snapshot_when_no_last_snapshot() throws Exception { | |||
ComponentDto project = insertComponent(newProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setLast(false)); | |||
reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); | |||
@@ -288,7 +292,8 @@ public class BuildComponentTreeStepTest { | |||
@Test | |||
public void set_base_project_snapshot_when_last_snapshot_exist() throws Exception { | |||
ComponentDto project = insertComponent(newProjectDto("ABCD").setKey(REPORT_PROJECT_KEY)); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = insertComponent(newProjectDto(organizationDto, "ABCD").setKey(REPORT_PROJECT_KEY)); | |||
insertSnapshot(newAnalysis(project).setLast(true)); | |||
reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY)); |
@@ -28,6 +28,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.MutableAnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.ReportComponent; | |||
@@ -54,7 +55,8 @@ public class EnableAnalysisStepTest { | |||
@Test | |||
public void switch_islast_flag_and_mark_analysis_as_processed() { | |||
ComponentDto project = ComponentTesting.newProjectDto(REPORT_PROJECT.getUuid()); | |||
OrganizationDto organization = db.organizations().insert(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organization, REPORT_PROJECT.getUuid()); | |||
db.getDbClient().componentDao().insert(db.getSession(), project); | |||
insertAnalysis(project, PREVIOUS_ANALYSIS_UUID, SnapshotDto.STATUS_PROCESSED, true); | |||
insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false); | |||
@@ -70,7 +72,7 @@ public class EnableAnalysisStepTest { | |||
@Test | |||
public void set_islast_flag_and_mark_as_processed_if_no_previous_analysis() { | |||
ComponentDto project = ComponentTesting.newProjectDto(REPORT_PROJECT.getUuid()); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), REPORT_PROJECT.getUuid()); | |||
db.getDbClient().componentDao().insert(db.getSession(), project); | |||
insertAnalysis(project, CURRENT_ANALYSIS_UUID, SnapshotDto.STATUS_UNPROCESSED, false); | |||
db.commit(); |
@@ -108,7 +108,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { | |||
@Before | |||
public void setUp() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, project); | |||
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project); | |||
dbClient.snapshotDao().insert(dbSession, projectSnapshot); | |||
@@ -326,7 +326,7 @@ public class LoadCrossProjectDuplicationsRepositoryStepTest { | |||
} | |||
private ComponentDto createProject(String projectKey) { | |||
ComponentDto project = ComponentTesting.newProjectDto().setKey(projectKey); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(projectKey); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); | |||
return project; |
@@ -38,6 +38,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.issue.IssueDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleTesting; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
@@ -98,7 +99,8 @@ public class PersistIssuesStepTest extends BaseStepTest { | |||
public void insert_new_issue() { | |||
RuleDto rule = RuleTesting.newDto(RuleKey.of("xoo", "S01")); | |||
dbClient.ruleDao().insert(session, rule); | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto); | |||
dbClient.componentDao().insert(session, project); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
dbClient.componentDao().insert(session, file); |
@@ -55,9 +55,9 @@ public class ReportComputeMeasureVariationsStepTest { | |||
private static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); | |||
private static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); | |||
private static final Metric NEW_DEBT = new MetricImpl(5, "new_debt", "new_debt", Metric.MetricType.WORK_DUR); | |||
private static final ComponentDto PROJECT_DTO = ComponentTesting.newProjectDto(); | |||
private static final String PROJECT_UUID = "prj uuid"; | |||
private static final int PROJECT_REF = 1; | |||
private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).setUuid(PROJECT_DTO.uuid()).build(); | |||
private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, PROJECT_REF).setUuid(PROJECT_UUID).build(); | |||
@Rule | |||
@@ -78,6 +78,8 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Rule | |||
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); | |||
private ComponentDto project; | |||
DbSession session = dbTester.getSession(); | |||
DbClient dbClient = dbTester.getDbClient(); | |||
@@ -86,17 +88,16 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Before | |||
public void setUp() { | |||
dbClient.componentDao().insert(session, PROJECT_DTO); | |||
session.commit(); | |||
project = dbTester.components().insertProject(dbTester.organizations().insert(), PROJECT_UUID); | |||
underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository); | |||
} | |||
@Test | |||
public void do_nothing_when_no_raw_measure() { | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); | |||
@@ -110,7 +111,7 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void do_nothing_when_no_period() { | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_DTO.uuid()).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).build(); | |||
treeRootHolder.setRoot(project); | |||
periodsHolder.setPeriods(); | |||
@@ -122,12 +123,12 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variation() { | |||
// Project | |||
SnapshotDto period1Snapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1Snapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1Snapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1Snapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1Snapshot.getUuid(), 60d)); | |||
// Directory | |||
ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir"); | |||
ComponentDto directoryDto = ComponentTesting.newDirectory(project, "dir"); | |||
dbClient.componentDao().insert(session, directoryDto); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d)); | |||
session.commit(); | |||
@@ -135,7 +136,7 @@ public class ReportComputeMeasureVariationsStepTest { | |||
periodsHolder.setPeriods(newPeriod(1, period1Snapshot)); | |||
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_DTO.uuid()).addChildren(directory).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build(); | |||
treeRootHolder.setRoot(project); | |||
addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(80, null)); | |||
@@ -150,12 +151,12 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_zero_variation_when_no_change() { | |||
// Project | |||
SnapshotDto period1Snapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1Snapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1Snapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1Snapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1Snapshot.getUuid(), 60d)); | |||
// Directory | |||
ComponentDto directoryDto = ComponentTesting.newDirectory(PROJECT_DTO, "dir"); | |||
ComponentDto directoryDto = ComponentTesting.newDirectory(project, "dir"); | |||
dbClient.componentDao().insert(session, directoryDto); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d)); | |||
session.commit(); | |||
@@ -163,7 +164,7 @@ public class ReportComputeMeasureVariationsStepTest { | |||
periodsHolder.setPeriods(newPeriod(1, period1Snapshot)); | |||
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_DTO.uuid()).addChildren(directory).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build(); | |||
treeRootHolder.setRoot(project); | |||
addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(60, null)); | |||
@@ -178,19 +179,19 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variation_to_raw_value_on_new_component() throws Exception { | |||
// Project | |||
SnapshotDto past1ProjectSnapshot = newAnalysis(PROJECT_DTO).setCreatedAt(1000_000_000L); | |||
SnapshotDto currentProjectSnapshot = newAnalysis(PROJECT_DTO).setCreatedAt(2000_000_000L); | |||
SnapshotDto past1ProjectSnapshot = newAnalysis(project).setCreatedAt(1000_000_000L); | |||
SnapshotDto currentProjectSnapshot = newAnalysis(project).setCreatedAt(2000_000_000L); | |||
dbClient.snapshotDao().insert(session, past1ProjectSnapshot); | |||
dbClient.snapshotDao().insert(session, currentProjectSnapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), past1ProjectSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), currentProjectSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, past1ProjectSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, currentProjectSnapshot.getUuid(), 60d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, past1ProjectSnapshot)); | |||
// Directory has just been added => no snapshot | |||
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("DIRECTORY").build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_DTO.uuid()).addChildren(directory).build(); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build(); | |||
treeRootHolder.setRoot(project); | |||
addRawMeasure(project, ISSUES_METRIC, newMeasureBuilder().create(90, null)); | |||
@@ -205,19 +206,19 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variations_on_all_periods() { | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(PROJECT_DTO).setLast(false); | |||
SnapshotDto period2ProjectSnapshot = newAnalysis(PROJECT_DTO).setLast(false); | |||
SnapshotDto period3ProjectSnapshot = newAnalysis(PROJECT_DTO).setLast(false); | |||
SnapshotDto period4ProjectSnapshot = newAnalysis(PROJECT_DTO).setLast(false); | |||
SnapshotDto period5ProjectSnapshot = newAnalysis(PROJECT_DTO).setLast(false); | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(project).setLast(false); | |||
SnapshotDto period2ProjectSnapshot = newAnalysis(project).setLast(false); | |||
SnapshotDto period3ProjectSnapshot = newAnalysis(project).setLast(false); | |||
SnapshotDto period4ProjectSnapshot = newAnalysis(project).setLast(false); | |||
SnapshotDto period5ProjectSnapshot = newAnalysis(project).setLast(false); | |||
dbClient.snapshotDao().insert(session, period1ProjectSnapshot, period2ProjectSnapshot, period3ProjectSnapshot, period4ProjectSnapshot, period5ProjectSnapshot); | |||
dbClient.measureDao().insert(session, | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 0d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period2ProjectSnapshot.getUuid(), 20d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period3ProjectSnapshot.getUuid(), 40d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period4ProjectSnapshot.getUuid(), 80d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period5ProjectSnapshot.getUuid(), 100d)); | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 0d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period2ProjectSnapshot.getUuid(), 20d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period3ProjectSnapshot.getUuid(), 40d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period4ProjectSnapshot.getUuid(), 80d), | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period5ProjectSnapshot.getUuid(), 100d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot), | |||
@@ -245,13 +246,13 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variation_on_all_numeric_metrics() { | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); | |||
dbClient.measureDao().insert(session, | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 60d), | |||
newMeasureDto(DEBT_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 10d), | |||
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 2d), | |||
newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 1d)); | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d), | |||
newMeasureDto(DEBT_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 10d), | |||
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 2d), | |||
newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 1d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); | |||
@@ -275,10 +276,10 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void do_not_set_variations_on_numeric_metric_for_developer() { | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); | |||
dbClient.measureDao().insert(session, | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 60d)); | |||
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); | |||
@@ -297,9 +298,9 @@ public class ReportComputeMeasureVariationsStepTest { | |||
@Test | |||
public void does_not_update_existing_variations() throws Exception { | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(PROJECT_DTO); | |||
SnapshotDto period1ProjectSnapshot = newAnalysis(project); | |||
dbClient.snapshotDao().insert(session, period1ProjectSnapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_DTO.uuid(), period1ProjectSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ProjectSnapshot)); | |||
treeRootHolder.setRoot(PROJECT); |
@@ -32,6 +32,7 @@ import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotQuery; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.Component; | |||
@@ -98,7 +99,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_analysis() { | |||
ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
ComponentDto moduleDto = ComponentTesting.newModuleDto("BCDE", projectDto).setKey("MODULE_KEY").setName("Module"); | |||
dbClient.componentDao().insert(dbTester.getSession(), moduleDto); | |||
@@ -139,7 +141,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_snapshots_with_periods() { | |||
ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime()); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); | |||
@@ -162,7 +165,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
public void only_persist_snapshots_with_periods_on_project_and_module() { | |||
periodsHolder.setPeriods(new Period(1, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1")); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(projectDto); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), projectSnapshot); | |||
@@ -197,7 +201,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { | |||
@Test | |||
public void set_no_period_on_snapshots_when_no_period() { | |||
ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); |
@@ -232,7 +232,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_only_new_components() { | |||
// Project amd module already exists | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module"); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -386,7 +386,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void nothing_to_persist() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module"); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -461,7 +461,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_module_name_and_description() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project").setDescription("Project description"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setDescription("Project description"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module"); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -500,7 +500,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_module_path() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module").setPath("path"); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -527,7 +527,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_module_uuid_when_moving_a_module() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto moduleA = ComponentTesting.newModuleDto("EDCB", project) | |||
.setKey("MODULE_A") | |||
@@ -604,7 +604,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void do_not_update_created_at_on_existing_component() { | |||
Date oldDate = DateUtils.parseDate("2015-01-01"); | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project").setCreatedAt(oldDate); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project").setCreatedAt(oldDate); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module").setPath("path").setCreatedAt(oldDate); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -622,7 +622,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_components_that_were_previously_removed() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto removedModule = ComponentTesting.newModuleDto("BCDE", project) | |||
.setKey(MODULE_KEY) | |||
@@ -724,7 +724,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_module_uuid_when_reactivating_removed_component() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setKey(MODULE_KEY).setName("Module"); | |||
ComponentDto removedModule = ComponentTesting.newModuleDto("EDCD", project).setKey("REMOVED_MODULE_KEY").setName("Removed Module").setEnabled(false); |
@@ -31,6 +31,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
@@ -76,7 +77,7 @@ public class ValidateProjectStepTest { | |||
.build()); | |||
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build()); | |||
ComponentDto project = ComponentTesting.newView("ABCD").setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newView(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
dbTester.getSession().commit(); | |||
@@ -158,7 +159,7 @@ public class ValidateProjectStepTest { | |||
.setKey(MODULE_KEY) | |||
.build()); | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(MODULE_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(MODULE_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
dbTester.getSession().commit(); | |||
@@ -190,8 +191,9 @@ public class ValidateProjectStepTest { | |||
.setKey(MODULE_KEY) | |||
.build()); | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY); | |||
ComponentDto anotherProject = ComponentTesting.newProjectDto().setKey(anotherProjectKey); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setKey(PROJECT_KEY); | |||
ComponentDto anotherProject = ComponentTesting.newProjectDto(organizationDto).setKey(anotherProjectKey); | |||
dbClient.componentDao().insert(dbTester.getSession(), project, anotherProject); | |||
ComponentDto module = ComponentTesting.newModuleDto("BCDE", anotherProject).setKey(MODULE_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -224,7 +226,7 @@ public class ValidateProjectStepTest { | |||
.setKey(MODULE_KEY) | |||
.build()); | |||
ComponentDto anotherProject = ComponentTesting.newProjectDto().setKey(anotherProjectKey); | |||
ComponentDto anotherProject = ComponentTesting.newProjectDto(dbTester.organizations().insert()).setKey(anotherProjectKey); | |||
dbClient.componentDao().insert(dbTester.getSession(), anotherProject); | |||
ComponentDto module = ComponentTesting.newModuleDto("ABCD", anotherProject).setKey(PROJECT_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), module); | |||
@@ -253,7 +255,7 @@ public class ValidateProjectStepTest { | |||
.addChildRef(2) | |||
.build()); | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1420088400000L)); // 2015-01-01 | |||
dbTester.getSession().commit(); | |||
@@ -274,7 +276,7 @@ public class ValidateProjectStepTest { | |||
.addChildRef(2) | |||
.build()); | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "ABCD").setKey(PROJECT_KEY); | |||
dbClient.componentDao().insert(dbTester.getSession(), project); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), SnapshotTesting.newAnalysis(project).setCreatedAt(1433131200000L)); // 2015-06-01 | |||
dbTester.getSession().commit(); |
@@ -51,8 +51,8 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
private static final Metric DEBT_METRIC = new MetricImpl(2, "sqale_index", "sqale_index", Metric.MetricType.WORK_DUR); | |||
private static final Metric FILE_COMPLEXITY_METRIC = new MetricImpl(3, "file_complexity", "file_complexity", Metric.MetricType.FLOAT); | |||
private static final Metric BUILD_BREAKER_METRIC = new MetricImpl(4, "build_breaker", "build_breaker", Metric.MetricType.BOOL); | |||
private static final ComponentDto VIEW_DTO = ComponentTesting.newView(); | |||
private static final Component VIEW = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_DTO.uuid()).build(); | |||
private static final String VIEW_UUID = "view uuid"; | |||
private static final Component VIEW = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).build(); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@@ -80,21 +80,22 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
DbClient dbClient = dbTester.getDbClient(); | |||
private ComponentDto view; | |||
ComputeMeasureVariationsStep underTest; | |||
@Before | |||
public void setUp() { | |||
dbClient.componentDao().insert(session, VIEW_DTO); | |||
session.commit(); | |||
view = dbTester.components().insertView(dbTester.organizations().insert(), VIEW_UUID); | |||
underTest = new ComputeMeasureVariationsStep(dbClient, treeRootHolder, periodsHolder, metricRepository, measureRepository); | |||
} | |||
@Test | |||
public void do_nothing_when_no_raw_measure() { | |||
SnapshotDto period1ViewSnapshot = newAnalysis(VIEW_DTO); | |||
SnapshotDto period1ViewSnapshot = newAnalysis(view); | |||
dbClient.snapshotDao().insert(session, period1ViewSnapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot)); | |||
@@ -108,7 +109,7 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
@Test | |||
public void do_nothing_when_no_period() { | |||
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_DTO.uuid()).build(); | |||
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).build(); | |||
treeRootHolder.setRoot(view); | |||
periodsHolder.setPeriods(); | |||
@@ -120,12 +121,12 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variation() { | |||
// View | |||
SnapshotDto period1Snapshot = newAnalysis(VIEW_DTO); | |||
SnapshotDto period1Snapshot = newAnalysis(view); | |||
dbClient.snapshotDao().insert(session, period1Snapshot); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1Snapshot.getUuid(), 60d)); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1Snapshot.getUuid(), 60d)); | |||
// SubView | |||
ComponentDto subviewDto = ComponentTesting.newSubView(VIEW_DTO, "dir", "key"); | |||
ComponentDto subviewDto = ComponentTesting.newSubView(view, "dir", "key"); | |||
dbClient.componentDao().insert(session, subviewDto); | |||
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), subviewDto.uuid(), period1Snapshot.getUuid(), 10d)); | |||
session.commit(); | |||
@@ -133,7 +134,7 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
periodsHolder.setPeriods(newPeriod(1, period1Snapshot)); | |||
Component subview = ViewsComponent.builder(Component.Type.SUBVIEW, 2).setUuid(subviewDto.uuid()).build(); | |||
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_DTO.uuid()).addChildren(subview).build(); | |||
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).addChildren(subview).build(); | |||
treeRootHolder.setRoot(view); | |||
addRawMeasure(view, ISSUES_METRIC, Measure.newMeasureBuilder().create(80, null)); | |||
@@ -147,19 +148,19 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variations_on_all_periods() { | |||
SnapshotDto period1ViewSnapshot = newAnalysis(VIEW_DTO).setLast(false); | |||
SnapshotDto period2ViewSnapshot = newAnalysis(VIEW_DTO).setLast(false); | |||
SnapshotDto period3ViewSnapshot = newAnalysis(VIEW_DTO).setLast(false); | |||
SnapshotDto period4ViewSnapshot = newAnalysis(VIEW_DTO).setLast(false); | |||
SnapshotDto period5ViewSnapshot = newAnalysis(VIEW_DTO).setLast(false); | |||
SnapshotDto period1ViewSnapshot = newAnalysis(view).setLast(false); | |||
SnapshotDto period2ViewSnapshot = newAnalysis(view).setLast(false); | |||
SnapshotDto period3ViewSnapshot = newAnalysis(view).setLast(false); | |||
SnapshotDto period4ViewSnapshot = newAnalysis(view).setLast(false); | |||
SnapshotDto period5ViewSnapshot = newAnalysis(view).setLast(false); | |||
dbClient.snapshotDao().insert(session, period1ViewSnapshot, period2ViewSnapshot, period3ViewSnapshot, period4ViewSnapshot, period5ViewSnapshot); | |||
dbClient.measureDao().insert(session, | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 0d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period2ViewSnapshot.getUuid(), 20d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period3ViewSnapshot.getUuid(), 40d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period4ViewSnapshot.getUuid(), 80d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period5ViewSnapshot.getUuid(), 100d)); | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 0d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period2ViewSnapshot.getUuid(), 20d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period3ViewSnapshot.getUuid(), 40d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period4ViewSnapshot.getUuid(), 80d), | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period5ViewSnapshot.getUuid(), 100d)); | |||
session.commit(); | |||
periodsHolder.setPeriods(newPeriod(1, period1ViewSnapshot), | |||
@@ -187,13 +188,13 @@ public class ViewsComputeMeasureVariationsStepTest { | |||
@Test | |||
public void set_variation_on_all_numeric_metrics() { | |||
SnapshotDto period1ViewSnapshot = newAnalysis(VIEW_DTO); | |||
SnapshotDto period1ViewSnapshot = newAnalysis(view); | |||
dbClient.snapshotDao().insert(session, period1ViewSnapshot); | |||
dbClient.measureDao().insert(session, | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 60d), | |||
newMeasureDto(DEBT_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 10d), | |||
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 2d), | |||
newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_DTO.uuid(), period1ViewSnapshot.getUuid(), 1d) | |||
newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d), | |||
newMeasureDto(DEBT_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 10d), | |||
newMeasureDto(FILE_COMPLEXITY_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 2d), | |||
newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 1d) | |||
); | |||
session.commit(); | |||
@@ -30,6 +30,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotQuery; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.Component; | |||
@@ -95,9 +96,10 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_analysis() { | |||
ComponentDto viewDto = save(newView("UUID_VIEW").setKey("KEY_VIEW")); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setKey("KEY_VIEW")); | |||
save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); | |||
save(newProjectDto("proj")); | |||
save(newProjectDto(organizationDto, "proj")); | |||
dbTester.getSession().commit(); | |||
Component projectView = ViewsComponent.builder(PROJECT_VIEW, "KEY_PROJECT_COPY").setUuid("UUID_PROJECT_COPY").build(); | |||
@@ -121,7 +123,8 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_snapshots_with_periods() { | |||
ComponentDto viewDto = save(newView("UUID_VIEW").setKey("KEY_VIEW")); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto viewDto = save(newView(organizationDto, "UUID_VIEW").setKey("KEY_VIEW")); | |||
ComponentDto subViewDto = save(newSubView(viewDto, "UUID_SUBVIEW", "KEY_SUBVIEW")); | |||
dbTester.getSession().commit(); | |||
@@ -32,6 +32,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.MutableDbIdsRepositoryRule; | |||
import org.sonar.server.computation.task.projectanalysis.component.MutableDisabledComponentsHolder; | |||
@@ -112,7 +113,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_existing_empty_view() { | |||
// most of the time view already exists since its supposed to be created when config is uploaded | |||
persistComponents(newViewDto()); | |||
persistComponents(newViewDto(dbTester.organizations().insert())); | |||
treeRootHolder.setRoot(createViewBuilder().build()); | |||
@@ -125,7 +126,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_view_with_projectView() { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(dbTester.organizations().insert()); | |||
persistComponents(project); | |||
treeRootHolder.setRoot( | |||
@@ -165,7 +166,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_existing_empty_subview_under_existing_view() { | |||
ComponentDto viewDto = newViewDto(); | |||
ComponentDto viewDto = newViewDto(dbTester.organizations().insert()); | |||
persistComponents(viewDto); | |||
persistComponents(ComponentTesting.newSubView(viewDto, SUBVIEW_1_UUID, SUBVIEW_1_KEY).setName(SUBVIEW_1_NAME)); | |||
@@ -185,7 +186,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_empty_subview_under_existing_view() { | |||
persistComponents(newViewDto()); | |||
persistComponents(newViewDto(dbTester.organizations().insert())); | |||
treeRootHolder.setRoot( | |||
createViewBuilder() | |||
@@ -203,7 +204,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void persist_project_view_under_subview() { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(dbTester.organizations().insert()); | |||
persistComponents(project); | |||
treeRootHolder.setRoot( | |||
@@ -229,7 +230,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_view_name_and_longName() { | |||
ComponentDto viewDto = newViewDto().setLongName("another long name").setCreatedAt(now); | |||
ComponentDto viewDto = newViewDto(dbTester.organizations().insert()).setLongName("another long name").setCreatedAt(now); | |||
persistComponents(viewDto); | |||
treeRootHolder.setRoot(createViewBuilder().build()); | |||
@@ -247,8 +248,9 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_project_view() { | |||
ComponentDto view = newViewDto(); | |||
ComponentDto project = newProjectDto(); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto view = newViewDto(organizationDto); | |||
ComponentDto project = newProjectDto(organizationDto); | |||
persistComponents(view, project); | |||
ComponentDto projectView = ComponentTesting.newProjectCopy(PROJECT_VIEW_1_UUID, project, view) | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
@@ -275,9 +277,10 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
@Test | |||
public void update_copy_component_uuid_of_project_view() { | |||
ComponentDto view = newViewDto(); | |||
ComponentDto project1 = newProjectDto("P1"); | |||
ComponentDto project2 = newProjectDto("P2"); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto view = newViewDto(organizationDto); | |||
ComponentDto project1 = newProjectDto(organizationDto, "P1"); | |||
ComponentDto project2 = newProjectDto(organizationDto, "P2"); | |||
persistComponents(view, project1, project2); | |||
// Project view in DB is associated to project1 | |||
@@ -335,8 +338,8 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest { | |||
assertThat(getComponentFromDb(componentKey).getCreatedAt()).isNotEqualTo(now); | |||
} | |||
private ComponentDto newViewDto() { | |||
return ComponentTesting.newView(VIEW_UUID) | |||
private ComponentDto newViewDto(OrganizationDto organizationDto) { | |||
return ComponentTesting.newView(organizationDto, VIEW_UUID) | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setKey(VIEW_KEY) | |||
.setName(VIEW_NAME); |
@@ -33,6 +33,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.test.JsonAssert; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
@@ -58,7 +59,7 @@ public class DuplicationsJsonWriterTest { | |||
@Before | |||
public void setUp() { | |||
project = ComponentTesting.newProjectDto() | |||
project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto()) | |||
.setId(1L) | |||
.setName("SonarQube") | |||
.setLongName("SonarQube") |
@@ -36,6 +36,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
@@ -51,6 +52,8 @@ public class DuplicationsParserTest { | |||
ComponentDao componentDao = db.getDbClient().componentDao(); | |||
OrganizationDto organizationDto; | |||
ComponentDto currentFile; | |||
ComponentDto fileOnSameProject; | |||
ComponentDto fileOnDifferentProject; | |||
@@ -62,11 +65,12 @@ public class DuplicationsParserTest { | |||
@Before | |||
public void setUp() { | |||
project1 = newProjectDto() | |||
organizationDto = db.organizations().insert(); | |||
project1 = newProjectDto(organizationDto) | |||
.setName("SonarQube") | |||
.setLongName("SonarQube") | |||
.setKey("org.codehaus.sonar:sonar"); | |||
project2 = newProjectDto(); | |||
project2 = newProjectDto(organizationDto); | |||
componentDao.insert(dbSession, project1, project2); | |||
// Current file | |||
@@ -209,7 +213,7 @@ public class DuplicationsParserTest { | |||
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnSameProject, 5, 2), new DuplicationsParser.Duplication(fileOnDifferentProject, 2, 2))).isEqualTo(-1); | |||
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2), new DuplicationsParser.Duplication(fileOnSameProject, 2, 2))).isEqualTo(1); | |||
// Files on 2 different projects | |||
ComponentDto project3 = newProjectDto().setId(3L); | |||
ComponentDto project3 = newProjectDto(organizationDto).setId(3L); | |||
assertThat(comparator.compare(new DuplicationsParser.Duplication(fileOnDifferentProject, 5, 2), | |||
new DuplicationsParser.Duplication(project3, 2, 2))).isEqualTo(1); | |||
@@ -28,6 +28,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.property.PropertyQuery; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -38,7 +39,9 @@ import static org.sonar.db.component.ComponentTesting.newProjectDto; | |||
public class FavoriteUpdaterTest { | |||
private static final long COMPONENT_ID = 23L; | |||
private static final String COMPONENT_KEY = "K1"; | |||
private static final ComponentDto COMPONENT = newProjectDto().setId(COMPONENT_ID).setKey(COMPONENT_KEY); | |||
private static final ComponentDto COMPONENT = newProjectDto(OrganizationTesting.newOrganizationDto()) | |||
.setId(COMPONENT_ID) | |||
.setKey(COMPONENT_KEY); | |||
private static final long USER_ID = 42L; | |||
@Rule |
@@ -143,7 +143,7 @@ public class AddActionTest { | |||
} | |||
private ComponentDto insertProject() { | |||
return db.components().insertComponent(newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY)); | |||
return db.components().insertComponent(newProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY)); | |||
} | |||
private ComponentDto insertProjectAndPermissions() { |
@@ -113,7 +113,7 @@ public class RemoveActionTest { | |||
} | |||
private ComponentDto insertProject() { | |||
return db.components().insertComponent(newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY)); | |||
return db.components().insertComponent(newProjectDto(db.organizations().insert(), PROJECT_UUID).setKey(PROJECT_KEY)); | |||
} | |||
private ComponentDto insertProjectAndPermissions() { |
@@ -35,6 +35,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.permission.UserPermissionDto; | |||
import org.sonar.server.exceptions.UnauthorizedException; | |||
import org.sonar.server.favorite.FavoriteFinder; | |||
@@ -73,10 +74,10 @@ public class SearchActionTest { | |||
@Test | |||
public void return_favorites() { | |||
ComponentDto project = newProjectDto("P1").setKey("K1").setName("N1"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "P1").setKey("K1").setName("N1"); | |||
addComponent(project); | |||
addComponent(newFileDto(project).setKey("K11").setName("N11")); | |||
addComponent(newProjectDto("P2").setKey("K2").setName("N2")); | |||
addComponent(newProjectDto(db.getDefaultOrganization(), "P2").setKey("K2").setName("N2")); | |||
SearchResponse result = call(); | |||
@@ -101,8 +102,9 @@ public class SearchActionTest { | |||
@Test | |||
public void filter_authorized_components() { | |||
addComponent(newProjectDto().setKey("K1")); | |||
ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
addComponent(newProjectDto(organizationDto).setKey("K1")); | |||
ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto(organizationDto)); | |||
db.favorites().add(unauthorizedProject, USER_ID); | |||
SearchResponse result = call(); | |||
@@ -114,8 +116,8 @@ public class SearchActionTest { | |||
@Test | |||
public void paginate_results() { | |||
IntStream.rangeClosed(1, 9) | |||
.forEach(i -> addComponent(newProjectDto().setKey("K" + i).setName("N" + i))); | |||
ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto()); | |||
.forEach(i -> addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K" + i).setName("N" + i))); | |||
ComponentDto unauthorizedProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
db.favorites().add(unauthorizedProject, USER_ID); | |||
SearchResponse result = call(2, 3); | |||
@@ -129,8 +131,9 @@ public class SearchActionTest { | |||
@Test | |||
public void return_only_users_favorite() { | |||
addComponent(newProjectDto().setKey("K1")); | |||
ComponentDto otherUserFavorite = newProjectDto().setKey("K42"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
addComponent(newProjectDto(organizationDto).setKey("K1")); | |||
ComponentDto otherUserFavorite = newProjectDto(organizationDto).setKey("K42"); | |||
db.components().insertComponent(otherUserFavorite); | |||
db.favorites().add(otherUserFavorite, 42L); | |||
dbClient.userPermissionDao().insert(dbSession, new UserPermissionDto("O1", UserRole.USER, 42L, otherUserFavorite.getId())); | |||
@@ -143,9 +146,10 @@ public class SearchActionTest { | |||
@Test | |||
public void favorites_ordered_by_name() { | |||
addComponent(newProjectDto().setName("N2")); | |||
addComponent(newProjectDto().setName("N3")); | |||
addComponent(newProjectDto().setName("N1")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
addComponent(newProjectDto(organizationDto).setName("N2")); | |||
addComponent(newProjectDto(organizationDto).setName("N3")); | |||
addComponent(newProjectDto(organizationDto).setName("N1")); | |||
SearchResponse result = call(); | |||
@@ -155,9 +159,9 @@ public class SearchActionTest { | |||
@Test | |||
public void json_example() { | |||
addComponent(newProjectDto().setKey("K1").setName("Samba")); | |||
addComponent(newProjectDto().setKey("K2").setName("Apache HBase")); | |||
addComponent(newProjectDto().setKey("K3").setName("JDK9")); | |||
addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K1").setName("Samba")); | |||
addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K2").setName("Apache HBase")); | |||
addComponent(newProjectDto(db.getDefaultOrganization()).setKey("K3").setName("JDK9")); | |||
String result = ws.newRequest().execute().getInput(); | |||
@@ -24,6 +24,7 @@ import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.issue.IssueDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -47,7 +48,7 @@ public class ActionFinderTest { | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone().login("arthur"); | |||
private ComponentDto project = newProjectDto(PROJECT_UUID).setKey(PROJECT_KEY); | |||
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); | |||
private ActionFinder underTest = new ActionFinder(userSession); |
@@ -37,6 +37,9 @@ import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.issue.IssueDao; | |||
import org.sonar.db.issue.IssueDto; | |||
import org.sonar.db.issue.IssueTesting; | |||
import org.sonar.db.organization.OrganizationDao; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.rule.RuleDao; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.db.rule.RuleTesting; | |||
@@ -263,7 +266,9 @@ public class IssueServiceMediumTest { | |||
} | |||
private ComponentDto newProject() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
OrganizationDto organization = OrganizationTesting.newOrganizationDto(); | |||
tester.get(OrganizationDao.class).insert(session, organization); | |||
ComponentDto project = ComponentTesting.newProjectDto(organization); | |||
tester.get(ComponentDao.class).insert(session, project); | |||
userSessionRule.login("admin").addProjectPermissions(UserRole.USER, project.key()).setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); |
@@ -32,6 +32,7 @@ import org.sonar.core.issue.IssueChangeContext; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.issue.IssueDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.server.issue.workflow.FunctionExecutor; | |||
import org.sonar.server.issue.workflow.IssueWorkflow; | |||
@@ -113,7 +114,7 @@ public class TransitionActionTest { | |||
private IssueDto newIssue() { | |||
RuleDto rule = newRuleDto().setId(10); | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto()); | |||
ComponentDto file = (newFileDto(project)); | |||
return newDto(rule, file, project); | |||
} |
@@ -30,6 +30,7 @@ import org.sonar.core.issue.IssueChangeContext; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.issue.IssueDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.server.issue.workflow.FunctionExecutor; | |||
import org.sonar.server.issue.workflow.IssueWorkflow; | |||
@@ -100,7 +101,7 @@ public class TransitionServiceTest { | |||
private IssueDto newIssue() { | |||
RuleDto rule = newRuleDto().setId(10); | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto()); | |||
ComponentDto file = (newFileDto(project)); | |||
return newDto(rule, file, project); | |||
} |
@@ -34,6 +34,7 @@ import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.es.SearchOptions; | |||
import org.sonar.server.es.SearchResult; | |||
@@ -52,6 +53,7 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.entry; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; | |||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.DEPRECATED_FACET_MODE_DEBT; | |||
import static org.sonarqube.ws.client.issue.IssuesWsParameters.FACET_MODE_EFFORT; | |||
@@ -82,8 +84,9 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_projects() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto("EFGH"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "EFGH"); | |||
indexIssues( | |||
IssueDocTesting.newDoc("ISSUE1", ComponentTesting.newFileDto(project, null)).setEffort(10L), | |||
@@ -99,7 +102,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_components() { | |||
ComponentDto project = ComponentTesting.newProjectDto("A"); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto(), "A"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE"); | |||
ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF"); | |||
@@ -120,7 +123,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_directories() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo"); | |||
@@ -136,7 +139,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_severities() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -152,7 +155,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_statuses() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -168,7 +171,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_resolutions() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -184,7 +187,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_languages() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
RuleKey ruleKey = RuleKey.of("repo", "X1"); | |||
@@ -198,7 +201,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_assignees() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -215,7 +218,7 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void facets_on_authors() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -247,8 +250,9 @@ public class IssueIndexDebtTest { | |||
@Test | |||
public void deprecated_debt_facets() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto("EFGH"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "EFGH"); | |||
indexIssues( | |||
IssueDocTesting.newDoc("ISSUE1", ComponentTesting.newFileDto(project, null)).setEffort(10L), | |||
@@ -263,7 +267,7 @@ public class IssueIndexDebtTest { | |||
} | |||
protected SearchOptions fixtureForCreatedAtFacet() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setFuncCreationDate(DateUtils.parseDateTime("2011-04-25T01:05:13+0100")); |
@@ -44,6 +44,7 @@ import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.es.SearchOptions; | |||
import org.sonar.server.es.SearchResult; | |||
@@ -65,6 +66,7 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.api.utils.DateUtils.parseDate; | |||
import static org.sonar.api.utils.DateUtils.parseDateTime; | |||
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; | |||
public class IssueIndexTest { | |||
@@ -97,7 +99,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void get_by_key() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue = IssueDocTesting.newDoc("ISSUE1", file) | |||
.setEffort(100L); | |||
@@ -112,7 +114,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void get_by_key_with_attributes() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue = IssueDocTesting.newDoc("ISSUE1", file).setAttributes((KeyValueFormat.format(ImmutableMap.of("jira-issue-key", "SONAR-1234")))); | |||
indexIssues(issue); | |||
@@ -123,7 +125,7 @@ public class IssueIndexTest { | |||
@Test(expected = IllegalStateException.class) | |||
public void comments_field_is_not_available() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue = IssueDocTesting.newDoc("ISSUE1", file); | |||
indexIssues(issue); | |||
@@ -134,7 +136,7 @@ public class IssueIndexTest { | |||
@Test(expected = IllegalStateException.class) | |||
public void is_new_field_is_not_available() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue = IssueDocTesting.newDoc("ISSUE1", file); | |||
indexIssues(issue); | |||
@@ -150,7 +152,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_keys() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
indexIssues( | |||
IssueDocTesting.newDoc("1", ComponentTesting.newFileDto(project, null)), | |||
@@ -163,7 +165,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_projects() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
@@ -181,8 +183,9 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_projects() { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto("EFGH"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "EFGH"); | |||
indexIssues( | |||
IssueDocTesting.newDoc("ISSUE1", ComponentTesting.newFileDto(project, null)), | |||
@@ -196,7 +199,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_modules() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
ComponentDto file = ComponentTesting.newFileDto(subModule, null); | |||
@@ -229,7 +232,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_components_on_contextualized_search() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null); | |||
@@ -264,7 +267,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_components_on_non_contextualized_search() { | |||
ComponentDto project = ComponentTesting.newProjectDto("project"); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto(), "project"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "file1"); | |||
ComponentDto module = ComponentTesting.newModuleDto(project).setUuid("module"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(module, null, "file2"); | |||
@@ -295,7 +298,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_components() { | |||
ComponentDto project = ComponentTesting.newProjectDto("A"); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto(), "A"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "ABCD"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null, "BCDE"); | |||
ComponentDto file3 = ComponentTesting.newFileDto(project, null, "CDEF"); | |||
@@ -315,7 +318,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_directories() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo"); | |||
@@ -330,7 +333,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_directories() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null).setPath("src/main/xoo/F1.xoo"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null).setPath("F2.xoo"); | |||
@@ -345,9 +348,10 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_views() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto(); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto); | |||
indexIssues( | |||
// Project1 has 2 issues (one on a file and one on the project itself) | |||
IssueDocTesting.newDoc("ISSUE1", project1), | |||
@@ -371,7 +375,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_severities() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -385,7 +389,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_severities() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -400,7 +404,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_statuses() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -415,7 +419,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_statuses() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -430,7 +434,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_resolutions() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -447,7 +451,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_resolutions() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -462,7 +466,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_resolved() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -477,7 +481,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_rules() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
RuleKey ruleKey = RuleKey.of("repo", "X1"); | |||
@@ -489,7 +493,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_languages() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
RuleKey ruleKey = RuleKey.of("repo", "X1"); | |||
@@ -502,7 +506,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_languages() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
RuleKey ruleKey = RuleKey.of("repo", "X1"); | |||
@@ -515,7 +519,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_assignees() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -530,7 +534,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_assignees() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -546,7 +550,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_assignees_supports_dashes() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -563,7 +567,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_assigned() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -578,7 +582,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_authors() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -593,7 +597,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void facets_on_authors() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -609,7 +613,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_created_after() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -625,7 +629,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_created_before() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -641,7 +645,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_created_after_and_before() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -687,7 +691,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_create_after_and_before_take_into_account_timezone() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -734,7 +738,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void filter_by_created_at() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues(IssueDocTesting.newDoc("ISSUE1", file).setFuncCreationDate(parseDate("2014-09-20"))); | |||
@@ -874,7 +878,7 @@ public class IssueIndexTest { | |||
} | |||
private SearchOptions fixtureForCreatedAtFacet() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
IssueDoc issue0 = IssueDocTesting.newDoc("ISSUE0", file).setFuncCreationDate(parseDateTime("2011-04-25T00:05:13+0000")); | |||
@@ -892,7 +896,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void paging() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
for (int i = 0; i < 12; i++) { | |||
indexIssues(IssueDocTesting.newDoc("ISSUE" + i, file)); | |||
@@ -915,7 +919,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void search_with_max_limit() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
List<IssueDoc> issues = newArrayList(); | |||
for (int i = 0; i < 500; i++) { | |||
@@ -931,7 +935,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_status() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -954,7 +958,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_severity() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -983,7 +987,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_assignee() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -1005,7 +1009,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_creation_date() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -1027,7 +1031,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_update_date() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -1049,7 +1053,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_close_date() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
indexIssues( | |||
@@ -1074,7 +1078,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void sort_by_file_and_line() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo"); | |||
@@ -1115,11 +1119,12 @@ public class IssueIndexTest { | |||
@Test | |||
public void default_sort_is_by_creation_date_then_project_then_file_then_line_then_issue_key() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto("P1"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto, "P1"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null, "F1").setPath("src/main/xoo/org/sonar/samples/File.xoo"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project1, null, "F2").setPath("src/main/xoo/org/sonar/samples/File2.xoo"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto("P2"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto, "P2"); | |||
ComponentDto file3 = ComponentTesting.newFileDto(project2, null, "F3").setPath("src/main/xoo/org/sonar/samples/File3.xoo"); | |||
indexIssues( | |||
@@ -1144,9 +1149,10 @@ public class IssueIndexTest { | |||
@Test | |||
public void authorized_issues_on_groups() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto().setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto().setKey("project2"); | |||
ComponentDto project3 = ComponentTesting.newProjectDto().setKey("project3"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto).setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto).setKey("project2"); | |||
ComponentDto project3 = ComponentTesting.newProjectDto(organizationDto).setKey("project3"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null).setKey("file1"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project2, null).setKey("file2"); | |||
@@ -1177,9 +1183,10 @@ public class IssueIndexTest { | |||
@Test | |||
public void authorized_issues_on_user() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto().setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto().setKey("project2"); | |||
ComponentDto project3 = ComponentTesting.newProjectDto().setKey("project3"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto).setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto).setKey("project2"); | |||
ComponentDto project3 = ComponentTesting.newProjectDto(organizationDto).setKey("project3"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null).setKey("file1"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project2, null).setKey("file2"); | |||
@@ -1206,8 +1213,9 @@ public class IssueIndexTest { | |||
@Test | |||
public void authorized_issues_on_user_and_group() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto().setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto().setKey("project2"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto).setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto).setKey("project2"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null).setKey("file1"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project2, null).setKey("file2"); | |||
@@ -1222,7 +1230,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void search_issues_for_batch_return_needed_fields() { | |||
ComponentDto project = ComponentTesting.newProjectDto("PROJECT"); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto(), "PROJECT"); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null).setPath("src/File.xoo"); | |||
IssueDoc issue = IssueDocTesting.newDoc("ISSUE", file) | |||
@@ -1258,7 +1266,7 @@ public class IssueIndexTest { | |||
@Test | |||
public void search_issues_for_batch() { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(newOrganizationDto()); | |||
ComponentDto module = ComponentTesting.newModuleDto(project); | |||
ComponentDto subModule = ComponentTesting.newModuleDto(module); | |||
ComponentDto file = ComponentTesting.newFileDto(subModule, null); | |||
@@ -1274,7 +1282,7 @@ public class IssueIndexTest { | |||
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(module))).hasSize(3); | |||
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(subModule))).hasSize(2); | |||
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(file))).hasSize(1); | |||
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(ComponentTesting.newProjectDto()))).isEmpty(); | |||
assertThat(Lists.newArrayList(underTest.selectIssuesForBatch(ComponentTesting.newProjectDto(newOrganizationDto())))).isEmpty(); | |||
} | |||
@Test | |||
@@ -1289,8 +1297,9 @@ public class IssueIndexTest { | |||
@Test | |||
public void search_issues_for_batch_return_only_authorized_issues() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto().setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto().setKey("project2"); | |||
OrganizationDto organizationDto = newOrganizationDto(); | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organizationDto).setKey("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organizationDto).setKey("project2"); | |||
ComponentDto file1 = ComponentTesting.newFileDto(project1, null).setKey("file1"); | |||
ComponentDto file2 = ComponentTesting.newFileDto(project2, null).setKey("file2"); |
@@ -41,6 +41,7 @@ import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.measure.custom.CustomMeasureDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.metric.MetricTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.es.EsTester; | |||
@@ -272,7 +273,7 @@ public class CreateActionTest { | |||
@Test | |||
public void create_custom_measure_on_a_view() throws Exception { | |||
String viewUuid = "VIEW_UUID"; | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newView(viewUuid)); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newView(db.organizations().insert(), viewUuid)); | |||
dbSession.commit(); | |||
MetricDto metric = insertMetric(BOOL); | |||
@@ -293,7 +294,7 @@ public class CreateActionTest { | |||
public void create_custom_measure_on_a_sub_view() throws Exception { | |||
String subViewUuid = "SUB_VIEW_UUID"; | |||
ComponentDto view = ComponentTesting.newView(); | |||
ComponentDto view = ComponentTesting.newView(db.organizations().insert()); | |||
dbClient.componentDao().insert(dbSession, view); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newSubView(view, subViewUuid, "SUB_VIEW_KEY")); | |||
dbSession.commit(); | |||
@@ -409,7 +410,7 @@ public class CreateActionTest { | |||
@Test | |||
public void fail_when_metric_is_not_found_in_db() throws Exception { | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(DEFAULT_PROJECT_UUID)); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(db.organizations().insert(), DEFAULT_PROJECT_UUID)); | |||
dbSession.commit(); | |||
expectedException.expect(RowNotFoundException.class); | |||
@@ -474,7 +475,7 @@ public class CreateActionTest { | |||
public void fail_when_not_a_project() throws Exception { | |||
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(STRING.name()).setKey("metric-key"); | |||
dbClient.metricDao().insert(dbSession, metric); | |||
ComponentDto project = ComponentTesting.newProjectDto(DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), DEFAULT_PROJECT_UUID).setKey(DEFAULT_PROJECT_KEY); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newDirectory(project, "directory-uuid", "path/to/directory").setKey("directory-key")); | |||
dbSession.commit(); | |||
@@ -501,7 +502,8 @@ public class CreateActionTest { | |||
} | |||
private void insertProject(String projectUuid) { | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(projectUuid).setKey(DEFAULT_PROJECT_KEY)); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(organizationDto, projectUuid).setKey(DEFAULT_PROJECT_KEY)); | |||
dbSession.commit(); | |||
} | |||
} |
@@ -77,7 +77,7 @@ public class DeleteActionTest { | |||
@Test | |||
public void delete_in_db_when_admin_on_project() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("project-uuid"); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
dbClient.componentDao().insert(dbSession, project); | |||
userSessionRule.login("login").addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
long id = insertCustomMeasure(newCustomMeasureDto().setComponentUuid("project-uuid")); | |||
@@ -98,7 +98,7 @@ public class DeleteActionTest { | |||
public void fail_when_insufficient_permissions() throws Exception { | |||
expectedException.expect(ForbiddenException.class); | |||
userSessionRule.login("login"); | |||
ComponentDto project = ComponentTesting.newProjectDto("any-uuid"); | |||
ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), "any-uuid"); | |||
dbClient.componentDao().insert(dbSession, project); | |||
long id = insertCustomMeasure(newCustomMeasureDto().setComponentUuid("any-uuid")); | |||
@@ -228,7 +228,7 @@ public class MetricsActionTest { | |||
} | |||
private ComponentDto insertProject(String projectUuid, String projectKey) { | |||
ComponentDto project = ComponentTesting.newProjectDto(projectUuid) | |||
ComponentDto project = ComponentTesting.newProjectDto(db.getDefaultOrganization(), projectUuid) | |||
.setKey(projectKey); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); |
@@ -266,7 +266,7 @@ public class SearchActionTest { | |||
} | |||
private ComponentDto insertProject(String projectUuid, String projectKey) { | |||
ComponentDto project = ComponentTesting.newProjectDto(projectUuid) | |||
ComponentDto project = ComponentTesting.newProjectDto(db.organizations().insert(), projectUuid) | |||
.setKey(projectKey); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); |
@@ -36,6 +36,7 @@ import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.measure.custom.CustomMeasureDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.metric.MetricTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.es.EsTester; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
@@ -89,7 +90,7 @@ public class UpdateActionTest { | |||
@Test | |||
public void update_text_value_and_description_in_db() throws Exception { | |||
MetricDto metric = insertNewMetric(ValueType.STRING); | |||
ComponentDto component = insertNewProject("project-uuid"); | |||
ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid"); | |||
CustomMeasureDto customMeasure = newCustomMeasure(component, metric) | |||
.setDescription("custom-measure-description") | |||
.setTextValue("text-measure-value"); | |||
@@ -113,7 +114,8 @@ public class UpdateActionTest { | |||
@Test | |||
public void update_double_value_and_description_in_db() throws Exception { | |||
MetricDto metric = insertNewMetric(ValueType.INT); | |||
ComponentDto component = insertNewProject("project-uuid"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto component = db.components().insertProject(organizationDto, "project-uuid"); | |||
CustomMeasureDto customMeasure = newCustomMeasure(component, metric) | |||
.setDescription("custom-measure-description") | |||
.setValue(42d); | |||
@@ -138,7 +140,8 @@ public class UpdateActionTest { | |||
.setValueType(ValueType.STRING.name()) | |||
.setKey("metric-key"); | |||
dbClient.metricDao().insert(dbSession, metric); | |||
ComponentDto component = ComponentTesting.newProjectDto("project-uuid").setKey("project-key"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "project-uuid").setKey("project-key"); | |||
dbClient.componentDao().insert(dbSession, component); | |||
CustomMeasureDto customMeasure = newCustomMeasure(component, metric) | |||
.setCreatedAt(100_000_000L) | |||
@@ -164,7 +167,7 @@ public class UpdateActionTest { | |||
@Test | |||
public void update_value_only() throws Exception { | |||
MetricDto metric = insertNewMetric(ValueType.STRING); | |||
ComponentDto component = insertNewProject("project-uuid"); | |||
ComponentDto component = db.components().insertProject(db.getDefaultOrganization(), "project-uuid"); | |||
CustomMeasureDto customMeasure = newCustomMeasure(component, metric) | |||
.setDescription("custom-measure-description") | |||
.setTextValue("text-measure-value"); | |||
@@ -187,7 +190,8 @@ public class UpdateActionTest { | |||
@Test | |||
public void update_description_only() throws Exception { | |||
MetricDto metric = insertNewMetric(ValueType.STRING); | |||
ComponentDto component = insertNewProject("project-uuid"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto component = db.components().insertProject(organizationDto, "project-uuid"); | |||
CustomMeasureDto customMeasure = newCustomMeasure(component, metric) | |||
.setMetricId(metric.getId()) | |||
.setComponentUuid(component.uuid()) | |||
@@ -239,7 +243,7 @@ public class UpdateActionTest { | |||
expectedException.expect(ForbiddenException.class); | |||
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name()); | |||
dbClient.metricDao().insert(dbSession, metric); | |||
ComponentDto component = ComponentTesting.newProjectDto("project-uuid"); | |||
ComponentDto component = ComponentTesting.newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
dbClient.componentDao().insert(dbSession, component); | |||
CustomMeasureDto customMeasure = newCustomMeasureDto() | |||
.setMetricId(metric.getId()) | |||
@@ -263,7 +267,8 @@ public class UpdateActionTest { | |||
expectedException.expect(UnauthorizedException.class); | |||
MetricDto metric = MetricTesting.newMetricDto().setEnabled(true).setValueType(ValueType.STRING.name()); | |||
dbClient.metricDao().insert(dbSession, metric); | |||
ComponentDto component = ComponentTesting.newProjectDto("project-uuid"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto component = ComponentTesting.newProjectDto(organizationDto, "project-uuid"); | |||
dbClient.componentDao().insert(dbSession, component); | |||
CustomMeasureDto customMeasure = newCustomMeasureDto() | |||
.setMetricId(metric.getId()) | |||
@@ -307,12 +312,6 @@ public class UpdateActionTest { | |||
return metric; | |||
} | |||
private ComponentDto insertNewProject(String uuid) { | |||
ComponentDto component = ComponentTesting.newProjectDto(uuid); | |||
dbClient.componentDao().insert(dbSession, component); | |||
return component; | |||
} | |||
private CustomMeasureDto newCustomMeasure(ComponentDto project, MetricDto metric) { | |||
return newCustomMeasureDto() | |||
.setMetricId(metric.getId()) |
@@ -38,6 +38,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
@@ -101,7 +102,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void provided_project() { | |||
componentDb.insertComponent(newProjectDto(PROJECT_UUID)); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.USER, PROJECT_UUID); | |||
insertNclocMetric(); | |||
@@ -114,7 +115,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void without_additional_fields() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
insertNclocMetric(); | |||
String response = ws.newRequest() | |||
@@ -129,9 +130,9 @@ public class ComponentActionTest { | |||
@Test | |||
public void reference_uuid_in_the_response() { | |||
ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto view = newView("view-uuid"); | |||
ComponentDto view = newView(db.getDefaultOrganization(), "view-uuid"); | |||
componentDb.insertViewAndSnapshot(view); | |||
componentDb.insertComponent(newProjectCopy("project-uuid-copy", project, view)); | |||
insertNclocMetric(); | |||
@@ -145,9 +146,10 @@ public class ComponentActionTest { | |||
@Test | |||
public void developer_measure_by_developer_uuid() { | |||
ComponentDto developer = newDeveloper("developer-name"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto developer = newDeveloper(organizationDto, "developer-name"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(organizationDto, "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file = newFileDto(project, null, "file-uuid"); | |||
componentDb.insertComponent(file); | |||
@@ -168,9 +170,10 @@ public class ComponentActionTest { | |||
@Test | |||
public void developer_measure_by_developer_key() { | |||
ComponentDto developer = newDeveloper("developer-name"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto developer = newDeveloper(organizationDto, "developer-name"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
ComponentDto project = newProjectDto(PROJECT_UUID); | |||
ComponentDto project = newProjectDto(organizationDto, PROJECT_UUID); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file = newFileDto(project, null, "file-uuid"); | |||
componentDb.insertComponent(file); | |||
@@ -194,7 +197,7 @@ public class ComponentActionTest { | |||
expectedException.expect(NotFoundException.class); | |||
expectedException.expectMessage("Component id 'unknown-developer-id' not found"); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(PROJECT_UUID)); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); | |||
insertNclocMetric(); | |||
call(ws.newRequest() | |||
@@ -206,7 +209,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void fail_when_a_metric_is_not_found() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto(PROJECT_UUID)); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), PROJECT_UUID)); | |||
insertNclocMetric(); | |||
insertComplexityMetric(); | |||
@@ -218,7 +221,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void fail_when_empty_metric_keys_parameter() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto(PROJECT_UUID)); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), PROJECT_UUID)); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("At least one metric key must be provided"); | |||
@@ -229,7 +232,7 @@ public class ComponentActionTest { | |||
@Test | |||
public void fail_when_not_enough_permission() { | |||
userSession.setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(PROJECT_UUID)); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), PROJECT_UUID)); | |||
insertNclocMetric(); | |||
expectedException.expect(ForbiddenException.class); | |||
@@ -310,7 +313,7 @@ public class ComponentActionTest { | |||
} | |||
private void insertJsonExampleData() { | |||
ComponentDto project = newProjectDto(PROJECT_UUID); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), PROJECT_UUID); | |||
SnapshotDto projectSnapshot = SnapshotTesting.newAnalysis(project) | |||
.setPeriodDate(1, parseDateTime("2016-01-11T10:49:50+0100").getTime()) | |||
.setPeriodMode(1, "previous_version") |
@@ -639,7 +639,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_with_measures_only_and_no_metric_sort() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
insertNclocMetric(); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException |
@@ -43,6 +43,7 @@ import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
@@ -108,7 +109,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_measures() throws Exception { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization()); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
setBrowsePermissionOnUser(project); | |||
MetricDto coverage = insertCoverageMetric(); | |||
@@ -126,7 +127,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_measures_on_periods() throws Exception { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
setBrowsePermissionOnUser(project); | |||
MetricDto coverage = insertCoverageMetric(); | |||
@@ -153,11 +154,12 @@ public class SearchActionTest { | |||
public void sort_by_metric_key_then_project_name() throws Exception { | |||
MetricDto coverage = insertCoverageMetric(); | |||
MetricDto complexity = insertComplexityMetric(); | |||
ComponentDto project1 = newProjectDto().setName("C"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project1 = newProjectDto(organizationDto).setName("C"); | |||
SnapshotDto projectSnapshot1 = componentDb.insertProjectAndSnapshot(project1); | |||
ComponentDto project2 = newProjectDto().setName("A"); | |||
ComponentDto project2 = newProjectDto(organizationDto).setName("A"); | |||
SnapshotDto projectSnapshot2 = componentDb.insertProjectAndSnapshot(project2); | |||
ComponentDto project3 = newProjectDto().setName("B"); | |||
ComponentDto project3 = newProjectDto(organizationDto).setName("B"); | |||
SnapshotDto projectSnapshot3 = componentDb.insertProjectAndSnapshot(project3); | |||
setBrowsePermissionOnUser(project1, project2, project3); | |||
dbClient.measureDao().insert(dbSession, newMeasureDto(coverage, project1, projectSnapshot1).setValue(5.5d)); | |||
@@ -179,9 +181,9 @@ public class SearchActionTest { | |||
@Test | |||
public void only_returns_authorized_projects() { | |||
MetricDto metricDto = insertComplexityMetric(); | |||
ComponentDto project1 = newProjectDto(); | |||
ComponentDto project1 = newProjectDto(db.getDefaultOrganization()); | |||
SnapshotDto projectSnapshot1 = componentDb.insertProjectAndSnapshot(project1); | |||
ComponentDto project2 = newProjectDto(); | |||
ComponentDto project2 = newProjectDto(db.getDefaultOrganization()); | |||
SnapshotDto projectSnapshot2 = componentDb.insertProjectAndSnapshot(project2); | |||
dbClient.measureDao().insert(dbSession, | |||
newMeasureDto(metricDto, project1, projectSnapshot1).setValue(15.5d), | |||
@@ -368,9 +370,10 @@ public class SearchActionTest { | |||
private List<String> insertJsonExampleData() { | |||
List<String> projectKeys = new ArrayList<>(); | |||
ComponentDto project1 = newProjectDto().setKey("MY_PROJECT_1").setName("Project 1"); | |||
ComponentDto project2 = newProjectDto().setKey("MY_PROJECT_2").setName("Project 2"); | |||
ComponentDto project3 = newProjectDto().setKey("MY_PROJECT_3").setName("Project 3"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project1 = newProjectDto(organizationDto).setKey("MY_PROJECT_1").setName("Project 1"); | |||
ComponentDto project2 = newProjectDto(organizationDto).setKey("MY_PROJECT_2").setName("Project 2"); | |||
ComponentDto project3 = newProjectDto(organizationDto).setKey("MY_PROJECT_3").setName("Project 3"); | |||
projectKeys.addAll(asList(project1.key(), project2.key(), project3.key())); | |||
componentDb.insertComponents(project1, project2, project3); | |||
SnapshotDto projectSnapshot1 = dbClient.snapshotDao().insert(dbSession, newAnalysis(project1) |
@@ -197,7 +197,7 @@ public class AddActionTest { | |||
@Test | |||
public void fail_when_component_is_not_a_project() { | |||
db.components().insertViewAndSnapshot(newView().setKey("VIEW_1")); | |||
db.components().insertViewAndSnapshot(newView(db.organizations().insert()).setKey("VIEW_1")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Component 'VIEW_1' must be a project"); |
@@ -114,7 +114,7 @@ public class ListActionTest { | |||
@Test | |||
public void filter_unauthorized_projects() { | |||
ComponentDto project = addComponent(newProjectDto().setKey("K1")); | |||
ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey("K1")); | |||
ComponentDto anotherProject = db.components().insertProject(); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, project); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, anotherProject); | |||
@@ -149,7 +149,7 @@ public class ListActionTest { | |||
@Test | |||
public void filter_per_project_dispatchers() { | |||
ComponentDto project = addComponent(newProjectDto().setKey("K1")); | |||
ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey("K1")); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, project); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), "Unknown Notification", project); | |||
dbSession.commit(); | |||
@@ -161,7 +161,7 @@ public class ListActionTest { | |||
@Test | |||
public void order_with_global_then_by_channel_and_dispatcher() { | |||
ComponentDto project = addComponent(newProjectDto().setKey("K1")); | |||
ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey("K1")); | |||
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, null); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, null); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_NEW_ISSUES, null); | |||
@@ -184,7 +184,7 @@ public class ListActionTest { | |||
@Test | |||
public void json_example() { | |||
ComponentDto project = addComponent(newProjectDto().setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project")); | |||
ComponentDto project = addComponent(newProjectDto(db.organizations().insert()).setKey(KEY_PROJECT_EXAMPLE_001).setName("My Project")); | |||
notificationUpdater.add(dbSession, twitterChannel.getKey(), NOTIF_MY_NEW_ISSUES, null); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_MY_NEW_ISSUES, null); | |||
notificationUpdater.add(dbSession, emailChannel.getKey(), NOTIF_NEW_ISSUES, null); |
@@ -212,7 +212,7 @@ public class RemoveActionTest { | |||
@Test | |||
public void fail_when_component_is_not_a_project() { | |||
db.components().insertViewAndSnapshot(newView().setKey("VIEW_1")); | |||
db.components().insertViewAndSnapshot(newView(db.organizations().insert()).setKey("VIEW_1")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Component 'VIEW_1' must be a project"); |
@@ -33,6 +33,7 @@ import org.sonar.api.web.UserRole; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.permission.template.PermissionTemplateDbTester; | |||
import org.sonar.db.permission.template.PermissionTemplateDto; | |||
import org.sonar.db.user.GroupDto; | |||
@@ -46,11 +47,13 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION; | |||
import static org.sonar.db.component.ComponentTesting.newProjectDto; | |||
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto; | |||
import static org.sonar.db.user.GroupTesting.newGroupDto; | |||
public class PermissionTemplateServiceTest { | |||
private static final ComponentDto PROJECT = newProjectDto().setId(123L).setUuid("THE_PROJECT_UUID"); | |||
private static final OrganizationDto ORGANIZATION = newOrganizationDto().setUuid("org1"); | |||
private static final ComponentDto PROJECT = newProjectDto(ORGANIZATION).setId(123L).setUuid("THE_PROJECT_UUID"); | |||
private static final long NOW = 123456789L; | |||
@Rule |
@@ -129,7 +129,7 @@ public class PermissionIndexerDaoTest { | |||
public void select_by_projects_with_high_number_of_projects() throws Exception { | |||
List<String> projects = new ArrayList<>(); | |||
for (int i = 0; i < 350; i++) { | |||
ComponentDto project = ComponentTesting.newProjectDto(Integer.toString(i)); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), Integer.toString(i)); | |||
dbClient.componentDao().insert(dbSession, project); | |||
projects.add(project.uuid()); | |||
GroupPermissionDto dto = new GroupPermissionDto() |
@@ -90,7 +90,7 @@ public class PermissionIndexerTest { | |||
public void index_all_with_huge_number_of_projects() throws Exception { | |||
GroupDto group = userDbTester.insertGroup(); | |||
for (int i = 0; i < 1100; i++) { | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.getDefaultOrganization()); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project); | |||
GroupPermissionDto dto = new GroupPermissionDto() | |||
.setOrganizationUuid(group.getOrganizationUuid()) |
@@ -98,7 +98,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { | |||
@Test | |||
public void add_permission_to_project_referenced_by_its_id() throws Exception { | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators"); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
@@ -114,7 +114,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { | |||
@Test | |||
public void add_permission_to_project_referenced_by_its_key() throws Exception { | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators"); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
@@ -129,8 +129,9 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { | |||
@Test | |||
public void add_with_view_uuid() throws Exception { | |||
OrganizationDto organizationDto = db.getDefaultOrganization(); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators"); | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key")); | |||
ComponentDto view = db.components().insertComponent(newView(organizationDto, "view-uuid").setKey("view-key")); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
@@ -168,8 +169,9 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { | |||
@Test | |||
public void adding_a_project_permission_fails_if_component_is_not_a_project() throws Exception { | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "sonar-administrators"); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
OrganizationDto organizationDto = db.getDefaultOrganization(); | |||
GroupDto group = db.users().insertGroup(organizationDto, "sonar-administrators"); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project, null, "file-uuid")); | |||
loginAsAdminOnDefaultOrganization(); | |||
@@ -249,7 +251,7 @@ public class AddGroupActionTest extends BasePermissionWsTest<AddGroupAction> { | |||
@Test | |||
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception { | |||
GroupDto group = db.users().insertGroup(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert())); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); |
@@ -101,7 +101,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { | |||
@Test | |||
public void add_permission_to_view() throws Exception { | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key")); | |||
ComponentDto view = db.components().insertComponent(newView(db.organizations().insert(), "view-uuid").setKey("view-key")); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
@@ -141,7 +141,7 @@ public class AddUserActionTest extends BasePermissionWsTest<AddUserAction> { | |||
@Test | |||
public void fail_when_component_is_not_a_project() throws Exception { | |||
db.components().insertComponent(newFileDto(newProjectDto("project-uuid"), null, "file-uuid")); | |||
db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert(), "project-uuid"), null, "file-uuid")); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); |
@@ -152,15 +152,16 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void search_groups_with_project_permissions() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid")); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name"); | |||
OrganizationDto organizationDto = db.getDefaultOrganization(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid")); | |||
GroupDto group = db.users().insertGroup(organizationDto, "project-group-name"); | |||
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project); | |||
ComponentDto anotherProject = db.components().insertComponent(newProjectDto()); | |||
GroupDto anotherGroup = db.users().insertGroup(db.getDefaultOrganization(), "another-project-group-name"); | |||
ComponentDto anotherProject = db.components().insertComponent(newProjectDto(organizationDto)); | |||
GroupDto anotherGroup = db.users().insertGroup(organizationDto, "another-project-group-name"); | |||
db.users().insertProjectPermissionOnGroup(anotherGroup, ISSUE_ADMIN, anotherProject); | |||
GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission"); | |||
GroupDto groupWithoutPermission = db.users().insertGroup(organizationDto, "group-without-permission"); | |||
userSession.login().addProjectUuidPermissions(ADMIN, "project-uuid"); | |||
String result = newRequest() | |||
@@ -176,12 +177,13 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void return_also_groups_without_permission_when_search_query() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid")); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group-with-permission"); | |||
OrganizationDto organizationDto = db.getDefaultOrganization(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid")); | |||
GroupDto group = db.users().insertGroup(organizationDto, "group-with-permission"); | |||
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project); | |||
GroupDto groupWithoutPermission = db.users().insertGroup(db.getDefaultOrganization(), "group-without-permission"); | |||
GroupDto anotherGroup = db.users().insertGroup(db.getDefaultOrganization(), "another-group"); | |||
GroupDto groupWithoutPermission = db.users().insertGroup(organizationDto, "group-without-permission"); | |||
GroupDto anotherGroup = db.users().insertGroup(organizationDto, "another-group"); | |||
loginAsAdminOnDefaultOrganization(); | |||
String result = newRequest() | |||
@@ -198,7 +200,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void return_only_groups_with_permission_when_no_search_query() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name"); | |||
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project); | |||
@@ -217,8 +219,9 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void return_anyone_group_when_search_query_and_no_param_permission() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto("project-uuid")); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "group-with-permission"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto, "project-uuid")); | |||
GroupDto group = db.users().insertGroup(organizationDto, "group-with-permission"); | |||
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, project); | |||
loginAsAdminOnDefaultOrganization(); | |||
@@ -233,7 +236,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void search_groups_on_views() throws Exception { | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key")); | |||
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid").setKey("view-key")); | |||
GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "project-group-name"); | |||
db.users().insertProjectPermissionOnGroup(group, ISSUE_ADMIN, view); | |||
@@ -272,7 +275,7 @@ public class GroupsActionTest extends BasePermissionWsTest<GroupsAction> { | |||
@Test | |||
public void fail_if_project_uuid_and_project_key_are_provided() throws Exception { | |||
db.components().insertComponent(newProjectDto("project-uuid").setKey("project-key")); | |||
db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key")); | |||
expectedException.expect(BadRequestException.class); | |||
@@ -108,7 +108,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio | |||
@Test | |||
public void remove_with_view_uuid() throws Exception { | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key")); | |||
ComponentDto view = db.components().insertComponent(newView(db.organizations().insert(), "view-uuid").setKey("view-key")); | |||
db.users().insertPermissionOnGroup(aGroup, SYSTEM_ADMIN); | |||
db.users().insertProjectPermissionOnGroup(aGroup, ADMIN, view); | |||
db.users().insertProjectPermissionOnGroup(aGroup, ISSUE_ADMIN, view); | |||
@@ -180,7 +180,7 @@ public class RemoveGroupActionTest extends BasePermissionWsTest<RemoveGroupActio | |||
@Test | |||
public void fail_when_component_is_not_a_project() throws Exception { | |||
ComponentDto file = db.components().insertComponent(newFileDto(newProjectDto(), null, "file-uuid")); | |||
ComponentDto file = db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid")); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); |
@@ -95,7 +95,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> | |||
@Test | |||
public void remove_permission_from_project() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); | |||
loginAsAdminOnDefaultOrganization(); | |||
@@ -111,7 +111,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> | |||
@Test | |||
public void remove_with_project_key() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); | |||
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, project); | |||
loginAsAdminOnDefaultOrganization(); | |||
@@ -127,7 +127,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> | |||
@Test | |||
public void remove_with_view_uuid() throws Exception { | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid").setKey("view-key")); | |||
ComponentDto view = db.components().insertComponent(newView(db.organizations().insert(), "view-uuid").setKey("view-key")); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, view); | |||
db.users().insertProjectPermissionOnUser(user, CODEVIEWER, view); | |||
loginAsAdminOnDefaultOrganization(); | |||
@@ -168,7 +168,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> | |||
@Test | |||
public void fail_when_component_is_not_a_project() throws Exception { | |||
db.components().insertComponent(newFileDto(newProjectDto(), null, "file-uuid")); | |||
db.components().insertComponent(newFileDto(newProjectDto(db.organizations().insert()), null, "file-uuid")); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); | |||
@@ -217,7 +217,7 @@ public class RemoveUserActionTest extends BasePermissionWsTest<RemoveUserAction> | |||
@Test | |||
public void fail_when_project_uuid_and_project_key_are_provided() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto(A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert(), A_PROJECT_UUID).setKey(A_PROJECT_KEY)); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); |
@@ -28,6 +28,7 @@ import org.sonar.core.permission.GlobalPermissions; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ResourceTypesRule; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
@@ -123,7 +124,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void search_project_permissions_with_project_permission() throws Exception { | |||
userSession.login().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
db.components().insertComponent(newProjectDto("project-uuid")); | |||
db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
String result = newRequest() | |||
.setParam(PARAM_PROJECT_ID, "project-uuid") | |||
@@ -134,8 +135,9 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void has_projects_ordered_by_name() throws Exception { | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
for (int i = 9; i >= 1; i--) { | |||
db.components().insertComponent(newProjectDto() | |||
db.components().insertComponent(newProjectDto(organizationDto) | |||
.setName("project-name-" + i)); | |||
} | |||
@@ -151,8 +153,8 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void search_by_query_on_name() throws Exception { | |||
componentDb.insertProjectAndSnapshot(newProjectDto().setName("project-name")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto().setName("another-name")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("project-name")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization()).setName("another-name")); | |||
componentDb.indexAllComponents(); | |||
String result = newRequest() | |||
@@ -165,8 +167,9 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void search_by_query_on_key_must_match_exactly() throws Exception { | |||
componentDb.insertProjectAndSnapshot(newProjectDto().setKey("project-key")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto().setKey("another-key")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setKey("project-key")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(organizationDto).setKey("another-key")); | |||
componentDb.indexAllComponents(); | |||
String result = newRequest() | |||
@@ -181,7 +184,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void handle_more_than_1000_projects() throws Exception { | |||
for (int i = 1; i <= 1001; i++) { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid-" + i)); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid-" + i)); | |||
} | |||
componentDb.indexAllComponents(); | |||
@@ -196,9 +199,10 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
@Test | |||
public void filter_by_qualifier() throws Exception { | |||
db.components().insertComponent(newView("view-uuid")); | |||
db.components().insertComponent(newDeveloper("developer-name")); | |||
db.components().insertComponent(newProjectDto("project-uuid")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
db.components().insertComponent(newView(organizationDto, "view-uuid")); | |||
db.components().insertComponent(newDeveloper(organizationDto, "developer-name")); | |||
db.components().insertComponent(newProjectDto(organizationDto, "project-uuid")); | |||
InputStream wsResponse = newRequest() | |||
.setMediaType(MediaTypes.PROTOBUF) | |||
@@ -242,7 +246,7 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
} | |||
private ComponentDto insertView() { | |||
return db.components().insertComponent(newView() | |||
return db.components().insertComponent(newView(db.organizations().insert()) | |||
.setUuid("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") | |||
.setName("Java") | |||
.setKey("Java")); | |||
@@ -253,20 +257,20 @@ public class SearchProjectPermissionsActionTest extends BasePermissionWsTest<Sea | |||
} | |||
private ComponentDto insertDeveloper() { | |||
return db.components().insertComponent(newDeveloper("Simon Brandhof") | |||
return db.components().insertComponent(newDeveloper(db.getDefaultOrganization(), "Simon Brandhof") | |||
.setUuid("4e607bf9-7ed0-484a-946d-d58ba7dab2fb") | |||
.setKey("simon-brandhof")); | |||
} | |||
private ComponentDto insertClang() { | |||
return db.components().insertComponent(newProjectDto("project-uuid-2") | |||
return db.components().insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid-2") | |||
.setName("Clang") | |||
.setKey("clang") | |||
.setUuid("ce4c03d6-430f-40a9-b777-ad877c00aa4d")); | |||
} | |||
private ComponentDto insertJdk7() { | |||
return db.components().insertComponent(newProjectDto("project-uuid-1") | |||
return db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid-1") | |||
.setName("JDK 7") | |||
.setKey("net.java.openjdk:jdk7") | |||
.setUuid("0bd7b1e7-91d6-439e-a607-4a3a9aad3c6a")); |
@@ -78,12 +78,12 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { | |||
@Test | |||
public void search_for_users_with_permission_on_project() throws Exception { | |||
// User has permission on project | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
UserDto user = db.users().insertUser(newUserDto()); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); | |||
// User has permission on another project | |||
ComponentDto anotherProject = db.components().insertComponent(newProjectDto()); | |||
ComponentDto anotherProject = db.components().insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
UserDto userHavePermissionOnAnotherProject = db.users().insertUser(newUserDto()); | |||
db.users().insertProjectPermissionOnUser(userHavePermissionOnAnotherProject, ISSUE_ADMIN, anotherProject); | |||
@@ -105,7 +105,7 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { | |||
@Test | |||
public void search_only_for_users_with_permission_when_no_search_query() throws Exception { | |||
// User have permission on project | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert())); | |||
UserDto user = db.users().insertUser(newUserDto()); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); | |||
@@ -125,7 +125,7 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { | |||
@Test | |||
public void search_also_for_users_without_permission_when_filtering_name() throws Exception { | |||
// User with permission on project | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert())); | |||
UserDto user = db.users().insertUser(newUserDto("with-permission", "with-permission", null)); | |||
db.users().insertProjectPermissionOnUser(user, ISSUE_ADMIN, project); | |||
@@ -210,7 +210,7 @@ public class UsersActionTest extends BasePermissionWsTest<UsersAction> { | |||
@Test | |||
public void fail_if_project_uuid_and_project_key_are_provided() throws Exception { | |||
db.components().insertComponent(newProjectDto("project-uuid").setKey("project-key")); | |||
db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key")); | |||
loginAsAdminOnDefaultOrganization(); | |||
expectedException.expect(BadRequestException.class); |
@@ -99,7 +99,7 @@ public class ApplyTemplateActionTest extends BasePermissionWsTest<ApplyTemplateA | |||
addGroupToTemplate(group1, template2, UserRole.USER); | |||
addGroupToTemplate(group2, template2, UserRole.USER); | |||
project = db.components().insertComponent(newProjectDto("project-uuid-1")); | |||
project = db.components().insertComponent(newProjectDto(db.organizations().insert(), "project-uuid-1")); | |||
db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, project); | |||
db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, project); | |||
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, project); |
@@ -88,9 +88,10 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT | |||
@Test | |||
public void bulk_apply_template_by_template_uuid() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto view = db.components().insertComponent(newView()); | |||
ComponentDto developer = db.components().insertComponent(newDeveloper("developer-name")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto)); | |||
ComponentDto view = db.components().insertComponent(newView(organizationDto)); | |||
ComponentDto developer = db.components().insertComponent(newDeveloper(organizationDto, "developer-name")); | |||
db.users().insertProjectPermissionOnUser(user1, UserRole.ADMIN, developer); | |||
db.users().insertProjectPermissionOnUser(user2, UserRole.ADMIN, developer); | |||
db.users().insertProjectPermissionOnGroup(group1, UserRole.ADMIN, developer); | |||
@@ -106,7 +107,7 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT | |||
@Test | |||
public void bulk_apply_template_by_template_name() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest().setParam(PARAM_TEMPLATE_NAME, template1.getName()).execute(); | |||
@@ -116,8 +117,9 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT | |||
@Test | |||
public void apply_template_by_qualifier() throws Exception { | |||
ComponentDto project = db.components().insertComponent(newProjectDto()); | |||
ComponentDto view = db.components().insertComponent(newView()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto)); | |||
ComponentDto view = db.components().insertComponent(newView(organizationDto)); | |||
loginAsAdminOnDefaultOrganization(); | |||
newRequest() | |||
@@ -130,12 +132,13 @@ public class BulkApplyTemplateActionTest extends BasePermissionWsTest<BulkApplyT | |||
@Test | |||
public void apply_template_by_query_on_name_and_key() throws Exception { | |||
ComponentDto projectFoundByKey = newProjectDto().setKey("sonar"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto projectFoundByKey = newProjectDto(organizationDto).setKey("sonar"); | |||
db.components().insertProjectAndSnapshot(projectFoundByKey); | |||
ComponentDto projectFoundByName = newProjectDto().setName("name-sonar-name"); | |||
ComponentDto projectFoundByName = newProjectDto(organizationDto).setName("name-sonar-name"); | |||
db.components().insertProjectAndSnapshot(projectFoundByName); | |||
// match must be exact on key | |||
ComponentDto projectUntouched = newProjectDto().setKey("new-sonar").setName("project-name"); | |||
ComponentDto projectUntouched = newProjectDto(organizationDto).setKey("new-sonar").setName("project-name"); | |||
db.components().insertProjectAndSnapshot(projectUntouched); | |||
db.components().indexAllComponents(); | |||
loginAsAdminOnDefaultOrganization(); |
@@ -199,7 +199,7 @@ public class DeleteActionTest { | |||
@Test | |||
public void fail_if_scope_is_not_project() throws Exception { | |||
expectedException.expect(IllegalArgumentException.class); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newFileDto(ComponentTesting.newProjectDto(), null, "file-uuid")); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newFileDto(ComponentTesting.newProjectDto(db.getDefaultOrganization()), null, "file-uuid")); | |||
dbSession.commit(); | |||
newRequest().setParam(PARAM_ID, "file-uuid").execute(); | |||
@@ -208,7 +208,7 @@ public class DeleteActionTest { | |||
@Test | |||
public void fail_if_qualifier_is_not_deletable() throws Exception { | |||
expectedException.expect(IllegalArgumentException.class); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto("project-uuid").setQualifier(Qualifiers.FILE)); | |||
dbClient.componentDao().insert(dbSession, ComponentTesting.newProjectDto(db.organizations().insert(), "project-uuid").setQualifier(Qualifiers.FILE)); | |||
dbSession.commit(); | |||
when(resourceType.getBooleanProperty(anyString())).thenReturn(false); | |||
@@ -218,7 +218,7 @@ public class DeleteActionTest { | |||
private long insertNewProjectInDbAndReturnSnapshotId(int id) { | |||
String suffix = String.valueOf(id); | |||
ComponentDto project = ComponentTesting | |||
.newProjectDto("project-uuid-" + suffix) | |||
.newProjectDto(db.organizations().insert(), "project-uuid-" + suffix) | |||
.setKey("project-key-" + suffix); | |||
RuleDto rule = RuleTesting.newDto(RuleKey.of("sonarqube", "rule-" + suffix)); | |||
dbClient.ruleDao().insert(dbSession, rule); | |||
@@ -234,7 +234,7 @@ public class DeleteActionTest { | |||
private void insertNewProjectInIndexes(int id) throws Exception { | |||
String suffix = String.valueOf(id); | |||
ComponentDto project = ComponentTesting | |||
.newProjectDto("project-uuid-" + suffix) | |||
.newProjectDto(db.getDefaultOrganization(), "project-uuid-" + suffix) | |||
.setKey("project-key-" + suffix); | |||
dbClient.componentDao().insert(dbSession, project); | |||
dbSession.commit(); |
@@ -33,6 +33,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsTester; | |||
@@ -126,14 +127,15 @@ public class GhostsActionTest { | |||
@Test | |||
public void ghost_projects_base_on_json_example() throws Exception { | |||
userSessionRule.setGlobalPermissions(UserRole.ADMIN); | |||
ComponentDto hBaseProject = ComponentTesting.newProjectDto("ce4c03d6-430f-40a9-b777-ad877c00aa4d") | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto hBaseProject = ComponentTesting.newProjectDto(organizationDto, "ce4c03d6-430f-40a9-b777-ad877c00aa4d") | |||
.setKey("org.apache.hbas:hbase") | |||
.setName("HBase") | |||
.setCreatedAt(DateUtils.parseDateTime("2015-03-04T23:03:44+0100")); | |||
dbClient.componentDao().insert(db.getSession(), hBaseProject); | |||
dbClient.snapshotDao().insert(db.getSession(), SnapshotTesting.newAnalysis(hBaseProject) | |||
.setStatus(SnapshotDto.STATUS_UNPROCESSED)); | |||
ComponentDto roslynProject = ComponentTesting.newProjectDto("c526ef20-131b-4486-9357-063fa64b5079") | |||
ComponentDto roslynProject = ComponentTesting.newProjectDto(organizationDto, "c526ef20-131b-4486-9357-063fa64b5079") | |||
.setKey("com.microsoft.roslyn:roslyn") | |||
.setName("Roslyn") | |||
.setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100")); | |||
@@ -156,7 +158,7 @@ public class GhostsActionTest { | |||
private void insertNewGhostProject(String id) { | |||
ComponentDto project = ComponentTesting | |||
.newProjectDto("ghost-uuid-" + id) | |||
.newProjectDto(db.organizations().insert(), "ghost-uuid-" + id) | |||
.setName("ghost-name-" + id) | |||
.setKey("ghost-key-" + id); | |||
dbClient.componentDao().insert(db.getSession(), project); | |||
@@ -168,7 +170,7 @@ public class GhostsActionTest { | |||
private void insertNewActiveProject(String id) { | |||
ComponentDto project = ComponentTesting | |||
.newProjectDto("analyzed-uuid-" + id) | |||
.newProjectDto(db.organizations().insert(), "analyzed-uuid-" + id) | |||
.setName("analyzed-name-" + id) | |||
.setKey("analyzed-key-" + id); | |||
dbClient.componentDao().insert(db.getSession(), project); |
@@ -36,6 +36,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsTester; | |||
@@ -68,8 +69,9 @@ public class ProvisionedActionTest { | |||
@Test | |||
public void all_provisioned_projects_without_analyzed_projects() throws Exception { | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.PROVISIONING); | |||
ComponentDto analyzedProject = ComponentTesting.newProjectDto("analyzed-uuid-1"); | |||
componentDao.insert(db.getSession(), newProvisionedProject("1"), newProvisionedProject("2"), analyzedProject); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto analyzedProject = ComponentTesting.newProjectDto(organizationDto, "analyzed-uuid-1"); | |||
componentDao.insert(db.getSession(), newProvisionedProject(organizationDto, "1"), newProvisionedProject(organizationDto, "2"), analyzedProject); | |||
SnapshotDto snapshot = SnapshotTesting.newAnalysis(analyzedProject); | |||
dbClient.snapshotDao().insert(db.getSession(), snapshot); | |||
db.getSession().commit(); | |||
@@ -83,8 +85,9 @@ public class ProvisionedActionTest { | |||
@Test | |||
public void provisioned_projects_with_correct_pagination() throws Exception { | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.PROVISIONING); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
for (int i = 1; i <= 10; i++) { | |||
componentDao.insert(db.getSession(), newProvisionedProject(String.valueOf(i))); | |||
componentDao.insert(db.getSession(), newProvisionedProject(organizationDto, String.valueOf(i))); | |||
} | |||
db.getSession().commit(); | |||
@@ -100,7 +103,7 @@ public class ProvisionedActionTest { | |||
@Test | |||
public void provisioned_projects_with_desired_fields() throws Exception { | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.PROVISIONING); | |||
componentDao.insert(db.getSession(), newProvisionedProject("1")); | |||
componentDao.insert(db.getSession(), newProvisionedProject(db.organizations().insert(), "1")); | |||
db.getSession().commit(); | |||
String jsonOutput = ws.newGetRequest("api/projects", "provisioned") | |||
@@ -115,7 +118,8 @@ public class ProvisionedActionTest { | |||
@Test | |||
public void provisioned_projects_with_query() throws Exception { | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.PROVISIONING); | |||
componentDao.insert(db.getSession(), newProvisionedProject("1"), newProvisionedProject("2")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
componentDao.insert(db.getSession(), newProvisionedProject(organizationDto, "1"), newProvisionedProject(organizationDto, "2")); | |||
db.getSession().commit(); | |||
String jsonOutput = ws.newGetRequest("api/projects", "provisioned") | |||
@@ -133,11 +137,12 @@ public class ProvisionedActionTest { | |||
@Test | |||
public void provisioned_projects_as_defined_in_the_example() throws Exception { | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.PROVISIONING); | |||
ComponentDto hBaseProject = ComponentTesting.newProjectDto("ce4c03d6-430f-40a9-b777-ad877c00aa4d") | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto hBaseProject = ComponentTesting.newProjectDto(organizationDto, "ce4c03d6-430f-40a9-b777-ad877c00aa4d") | |||
.setKey("org.apache.hbas:hbase") | |||
.setName("HBase") | |||
.setCreatedAt(DateUtils.parseDateTime("2015-03-04T23:03:44+0100")); | |||
ComponentDto roslynProject = ComponentTesting.newProjectDto("c526ef20-131b-4486-9357-063fa64b5079") | |||
ComponentDto roslynProject = ComponentTesting.newProjectDto(organizationDto, "c526ef20-131b-4486-9357-063fa64b5079") | |||
.setKey("com.microsoft.roslyn:roslyn") | |||
.setName("Roslyn") | |||
.setCreatedAt(DateUtils.parseDateTime("2013-03-04T23:03:44+0100")); | |||
@@ -153,14 +158,14 @@ public class ProvisionedActionTest { | |||
public void fail_when_not_enough_privileges() throws Exception { | |||
expectedException.expect(ForbiddenException.class); | |||
userSessionRule.setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION); | |||
componentDao.insert(db.getSession(), newProvisionedProject("1")); | |||
componentDao.insert(db.getSession(), newProvisionedProject(db.organizations().insert(), "1")); | |||
ws.newGetRequest("api/projects", "provisioned").execute(); | |||
} | |||
private static ComponentDto newProvisionedProject(String uuid) { | |||
private static ComponentDto newProvisionedProject(OrganizationDto organizationDto, String uuid) { | |||
return ComponentTesting | |||
.newProjectDto("provisioned-uuid-" + uuid) | |||
.newProjectDto(organizationDto, "provisioned-uuid-" + uuid) | |||
.setName("provisioned-name-" + uuid) | |||
.setKey("provisioned-key-" + uuid); | |||
} |
@@ -40,6 +40,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentLinkDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.user.GroupDto; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
@@ -92,8 +93,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void search_json_example() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto cLang = insertClang(); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto cLang = insertClang(organizationDto); | |||
dbClient.componentLinkDao().insert(dbSession, | |||
new ComponentLinkDto().setComponentUuid(jdk7.uuid()).setHref("http://www.oracle.com").setType(ComponentLinkDto.TYPE_HOME_PAGE).setName("Home")); | |||
dbClient.componentLinkDao().insert(dbSession, | |||
@@ -116,8 +118,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void return_only_current_user_projects() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto cLang = insertClang(); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto cLang = insertClang(organizationDto); | |||
UserDto anotherUser = db.users().insertUser(newUserDto()); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7); | |||
db.users().insertProjectPermissionOnUser(anotherUser, UserRole.ADMIN, cLang); | |||
@@ -130,9 +133,10 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void sort_projects_by_name() { | |||
ComponentDto b_project = db.components().insertComponent(newProjectDto().setName("B_project_name")); | |||
ComponentDto c_project = db.components().insertComponent(newProjectDto().setName("c_project_name")); | |||
ComponentDto a_project = db.components().insertComponent(newProjectDto().setName("A_project_name")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto b_project = db.components().insertComponent(newProjectDto(organizationDto).setName("B_project_name")); | |||
ComponentDto c_project = db.components().insertComponent(newProjectDto(organizationDto).setName("c_project_name")); | |||
ComponentDto a_project = db.components().insertComponent(newProjectDto(organizationDto).setName("A_project_name")); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, b_project); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, a_project); | |||
@@ -147,8 +151,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void paginate_projects() { | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
for (int i = 0; i < 10; i++) { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setName("project-" + i)); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setName("project-" + i)); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, project); | |||
} | |||
@@ -162,8 +167,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void return_only_projects_when_user_is_admin() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto clang = insertClang(); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto clang = insertClang(organizationDto); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ISSUE_ADMIN, clang); | |||
@@ -176,9 +182,10 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void do_not_return_views_or_developers() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto dev = insertDeveloper(); | |||
ComponentDto view = insertView(); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto dev = insertDeveloper(organizationDto); | |||
ComponentDto view = insertView(organizationDto); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, jdk7); | |||
db.users().insertProjectPermissionOnUser(user, UserRole.ADMIN, dev); | |||
@@ -192,8 +199,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void admin_via_groups() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto cLang = insertClang(); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto cLang = insertClang(organizationDto); | |||
GroupDto group = db.users().insertGroup(newGroupDto()); | |||
db.users().insertMember(group, user); | |||
@@ -209,9 +217,10 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void admin_via_groups_and_users() { | |||
ComponentDto jdk7 = insertJdk7(); | |||
ComponentDto cLang = insertClang(); | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto jdk7 = insertJdk7(organizationDto); | |||
ComponentDto cLang = insertClang(organizationDto); | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto(organizationDto)); | |||
GroupDto group = db.users().insertGroup(newGroupDto()); | |||
db.users().insertMember(group, user); | |||
@@ -230,9 +239,10 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void search_my_projects_by_name() { | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto().setName("ONE_PROJECT_NAME")); | |||
ComponentDto jdk8 = db.components().insertComponent(newProjectDto().setName("TWO_PROJECT_NAME")); | |||
ComponentDto ruby = db.components().insertComponent(newProjectDto().setName("ANOTHER_42")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto(organizationDto).setName("ONE_PROJECT_NAME")); | |||
ComponentDto jdk8 = db.components().insertComponent(newProjectDto(organizationDto).setName("TWO_PROJECT_NAME")); | |||
ComponentDto ruby = db.components().insertComponent(newProjectDto(organizationDto).setName("ANOTHER_42")); | |||
dbClient.snapshotDao().insert(dbSession, newAnalysis(sonarqube), newAnalysis(jdk8), newAnalysis(ruby)); | |||
db.components().indexAllComponents(); | |||
db.commit(); | |||
@@ -251,8 +261,9 @@ public class SearchMyProjectsActionTest { | |||
@Test | |||
public void search_my_projects_by_exact_match_on_key() { | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto().setKey("MY_PROJECT_KEY")); | |||
ComponentDto ruby = db.components().insertComponent(newProjectDto().setKey("MY_PROJECT_KEY_OR_ELSE")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto sonarqube = db.components().insertComponent(newProjectDto(organizationDto).setKey("MY_PROJECT_KEY")); | |||
ComponentDto ruby = db.components().insertComponent(newProjectDto(organizationDto).setKey("MY_PROJECT_KEY_OR_ELSE")); | |||
dbClient.snapshotDao().insert(dbSession, newAnalysis(sonarqube), newAnalysis(ruby)); | |||
db.components().indexAllComponents(); | |||
db.commit(); | |||
@@ -290,27 +301,27 @@ public class SearchMyProjectsActionTest { | |||
call_ws(ws.newRequest().setParam(TEXT_QUERY, "ab")); | |||
} | |||
private ComponentDto insertClang() { | |||
return db.components().insertComponent(newProjectDto(Uuids.UUID_EXAMPLE_01) | |||
private ComponentDto insertClang(OrganizationDto organizationDto) { | |||
return db.components().insertComponent(newProjectDto(organizationDto, Uuids.UUID_EXAMPLE_01) | |||
.setName("Clang") | |||
.setKey("clang")); | |||
} | |||
private ComponentDto insertJdk7() { | |||
return db.components().insertComponent(newProjectDto(Uuids.UUID_EXAMPLE_02) | |||
private ComponentDto insertJdk7(OrganizationDto organizationDto) { | |||
return db.components().insertComponent(newProjectDto(organizationDto, Uuids.UUID_EXAMPLE_02) | |||
.setName("JDK 7") | |||
.setKey("net.java.openjdk:jdk7") | |||
.setDescription("JDK")); | |||
} | |||
private ComponentDto insertView() { | |||
return db.components().insertComponent(newView("752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") | |||
private ComponentDto insertView(OrganizationDto organizationDto) { | |||
return db.components().insertComponent(newView(organizationDto, "752d8bfd-420c-4a83-a4e5-8ab19b13c8fc") | |||
.setName("Java") | |||
.setKey("Java")); | |||
} | |||
private ComponentDto insertDeveloper() { | |||
return db.components().insertComponent(newDeveloper("Joda", "4e607bf9-7ed0-484a-946d-d58ba7dab2fb") | |||
private ComponentDto insertDeveloper(OrganizationDto organizationDto) { | |||
return db.components().insertComponent(newDeveloper(organizationDto, "Joda", "4e607bf9-7ed0-484a-946d-d58ba7dab2fb") | |||
.setKey("joda")); | |||
} | |||
@@ -107,7 +107,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_event_in_db() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) | |||
@@ -131,7 +131,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_event_as_project_admin() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "P1")); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) | |||
@@ -145,7 +145,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_version_event() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) | |||
@@ -159,7 +159,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_other_event_with_ws_response() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setName("Project Import"); | |||
@@ -178,7 +178,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_event_without_description() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(OTHER) | |||
@@ -193,7 +193,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void create_2_version_events_on_same_project() { | |||
ComponentDto project = newProjectDto(); | |||
ComponentDto project = newProjectDto(db.organizations().insert()); | |||
SnapshotDto firstAnalysis = db.components().insertProjectAndSnapshot(project); | |||
CreateEventRequest.Builder firstRequest = CreateEventRequest.builder() | |||
.setAnalysis(firstAnalysis.getUuid()) | |||
@@ -215,7 +215,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void fail_if_not_blank_name() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder().setAnalysis(analysis.getUuid()).setName(" "); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -239,7 +239,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void fail_if_2_version_events_on_the_same_analysis() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) | |||
@@ -254,7 +254,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void fail_if_2_other_events_on_same_analysis_with_same_name() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(OTHER) | |||
@@ -271,7 +271,7 @@ public class CreateEventActionTest { | |||
public void fail_if_category_other_than_authorized() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization())); | |||
ws.newRequest() | |||
.setParam(PARAM_ANALYSIS, analysis.getUuid()) | |||
.setParam(PARAM_NAME, "Project Import") | |||
@@ -284,7 +284,7 @@ public class CreateEventActionTest { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("An event must be created on a project"); | |||
SnapshotDto analysis = db.components().insertViewAndSnapshot(newView()); | |||
SnapshotDto analysis = db.components().insertViewAndSnapshot(newView(db.organizations().insert())); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) | |||
@@ -310,7 +310,7 @@ public class CreateEventActionTest { | |||
@Test | |||
public void fail_if_insufficient_permissions() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "P1")); | |||
CreateEventRequest.Builder request = CreateEventRequest.builder() | |||
.setAnalysis(analysis.getUuid()) | |||
.setCategory(VERSION) |
@@ -62,7 +62,7 @@ public class DeleteEventActionTest { | |||
@Test | |||
public void delete_event() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E2")); | |||
@@ -86,7 +86,7 @@ public class DeleteEventActionTest { | |||
@Test | |||
public void delete_event_as_project_admin() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "P1")); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "P1"); | |||
@@ -109,7 +109,7 @@ public class DeleteEventActionTest { | |||
@Test | |||
public void fail_if_category_different_than_other_and_version() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "P1")); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory("Profile")); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -128,7 +128,7 @@ public class DeleteEventActionTest { | |||
@Test | |||
public void fail_if_not_enough_permission() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
userSession.anonymous(); | |||
@@ -25,6 +25,7 @@ import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.event.EventDto; | |||
import org.sonar.db.event.EventTesting; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import static org.sonar.db.component.ComponentTesting.newProjectDto; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
@@ -43,6 +44,6 @@ public class EventValidatorTest { | |||
} | |||
private EventDto newEvent() { | |||
return EventTesting.newEvent(newAnalysis(newProjectDto())); | |||
return EventTesting.newEvent(newAnalysis(newProjectDto(OrganizationTesting.newOrganizationDto()))); | |||
} | |||
} |
@@ -38,6 +38,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.event.EventDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
@@ -82,7 +83,8 @@ public class SearchActionTest { | |||
@Test | |||
public void json_example() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey(KEY_PROJECT_EXAMPLE_001)); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey(KEY_PROJECT_EXAMPLE_001)); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(parseDateTime("2016-12-11T17:12:45+0100").getTime())); | |||
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(parseDateTime("2016-12-12T17:12:45+0100").getTime())); | |||
@@ -107,7 +109,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_analyses_ordered_by_analysis_date() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey("P1")); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1")); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L)); | |||
db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L)); | |||
@@ -124,7 +126,7 @@ public class SearchActionTest { | |||
@Test | |||
public void return_only_processed_analyses() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey("P1")); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.getDefaultOrganization()).setKey("P1")); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); | |||
db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setStatus(SnapshotDto.STATUS_UNPROCESSED)); | |||
@@ -137,10 +139,11 @@ public class SearchActionTest { | |||
@Test | |||
public void return_events() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey("P1")); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(organizationDto).setKey("P1")); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); | |||
SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto()).setUuid("A42")); | |||
SnapshotDto a42 = db.components().insertSnapshot(newAnalysis(newProjectDto(organizationDto)).setUuid("A42")); | |||
EventDto e1 = db.events().insertEvent(newEvent(a1).setUuid("E1").setName("N1").setCategory(EventCategory.QUALITY_GATE.getLabel()).setDescription("D1")); | |||
EventDto e2 = db.events().insertEvent(newEvent(a1).setUuid("E2").setName("N2").setCategory(VERSION.getLabel()).setDescription("D2")); | |||
db.events().insertEvent(newEvent(a42)); | |||
@@ -173,7 +176,7 @@ public class SearchActionTest { | |||
@Test | |||
public void filter_by_category() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey("P1")); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1")); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1")); | |||
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2")); | |||
@@ -194,7 +197,7 @@ public class SearchActionTest { | |||
@Test | |||
public void paginate_with_filter_on_category() { | |||
ComponentDto project = db.components().insertComponent(newProjectDto().setKey("P1")); | |||
ComponentDto project = db.components().insertComponent(newProjectDto(db.organizations().insert()).setKey("P1")); | |||
userSession.addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
SnapshotDto a1 = db.components().insertSnapshot(newAnalysis(project).setUuid("A1").setCreatedAt(1_000_000L)); | |||
SnapshotDto a2 = db.components().insertSnapshot(newAnalysis(project).setUuid("A2").setCreatedAt(2_000_000L)); |
@@ -89,7 +89,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void update_name_in_db() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); | |||
call("E1", "name"); | |||
@@ -104,7 +104,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void ws_response_with_updated_name() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); | |||
ProjectAnalyses.Event result = call("E1", "name").getEvent(); | |||
@@ -142,7 +142,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void update_name_only_in_db() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
EventDto originalEvent = db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name").setDescription("Original Description")); | |||
call("E1", "name"); | |||
@@ -154,7 +154,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void update_as_project_admin() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto("P1")); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert(), "P1")); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setName("Original Name")); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "P1"); | |||
@@ -178,7 +178,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void fail_if_insufficient_permissions() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
userSession.anonymous(); | |||
@@ -197,7 +197,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void fail_if_no_name() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
expectedException.expect(NullPointerException.class); | |||
@@ -207,7 +207,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void fail_if_blank_name() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1")); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -218,7 +218,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void fail_if_category_other_than_other_or_version() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory("Profile")); | |||
expectedException.expect(IllegalArgumentException.class); | |||
@@ -229,7 +229,7 @@ public class UpdateEventActionTest { | |||
@Test | |||
public void fail_if_other_event_with_same_name_on_same_analysis() { | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto()); | |||
SnapshotDto analysis = db.components().insertProjectAndSnapshot(newProjectDto(db.organizations().insert())); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(OTHER.getLabel()).setName("E1 name")); | |||
db.events().insertEvent(newEvent(analysis).setUuid("E2").setCategory(OTHER.getLabel()).setName("E2 name")); | |||
@@ -220,7 +220,7 @@ public class SearchActionTest { | |||
} | |||
private ComponentDto insertProject(String projectKey, String projectUuid) { | |||
return componentDb.insertComponent(newProjectDto(projectUuid).setKey(projectKey)); | |||
return componentDb.insertComponent(newProjectDto(db.organizations().insert(), projectUuid).setKey(projectKey)); | |||
} | |||
private ComponentDto insertProject() { |
@@ -35,6 +35,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.db.qualitygate.ProjectQgateAssociation; | |||
import org.sonar.db.qualitygate.QualityGateDto; | |||
@@ -87,8 +88,9 @@ public class QgateProjectFinderTest { | |||
@Test | |||
public void return_all_projects() throws Exception { | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto()); | |||
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto()); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
associateProjectToQualitGate(associatedProject.getId()); | |||
Association result = underTest.find( | |||
@@ -105,8 +107,9 @@ public class QgateProjectFinderTest { | |||
@Test | |||
public void return_only_associated_project() throws Exception { | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto()); | |||
insertProjectAuthorizedToAnyone(newProjectDto()); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
associateProjectToQualitGate(associatedProject.getId()); | |||
Association result = underTest.find( | |||
@@ -122,8 +125,9 @@ public class QgateProjectFinderTest { | |||
@Test | |||
public void return_only_unassociated_project() throws Exception { | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto()); | |||
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto()); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto associatedProject = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
ComponentDto unassociatedProject = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto)); | |||
associateProjectToQualitGate(associatedProject.getId()); | |||
Association result = underTest.find( | |||
@@ -140,8 +144,9 @@ public class QgateProjectFinderTest { | |||
@Test | |||
public void return_only_authorized_projects() throws Exception { | |||
UserDto user = dbTester.users().insertUser("a_login"); | |||
ComponentDto project1 = componentDbTester.insertComponent(newProjectDto()); | |||
componentDbTester.insertComponent(newProjectDto()); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project1 = componentDbTester.insertComponent(newProjectDto(organizationDto)); | |||
componentDbTester.insertComponent(newProjectDto(organizationDto)); | |||
// User can only see project 1 | |||
dbTester.users().insertProjectPermissionOnUser(user, UserRole.USER, project1); | |||
@@ -157,9 +162,10 @@ public class QgateProjectFinderTest { | |||
@Test | |||
public void test_paging() throws Exception { | |||
ComponentDto project1 = insertProjectAuthorizedToAnyone(newProjectDto().setName("Project 1")); | |||
ComponentDto project2 = insertProjectAuthorizedToAnyone(newProjectDto().setName("Project 2")); | |||
ComponentDto project3 = insertProjectAuthorizedToAnyone(newProjectDto().setName("Project 3")); | |||
OrganizationDto organizationDto = dbTester.organizations().insert(); | |||
ComponentDto project1 = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto).setName("Project 1")); | |||
ComponentDto project2 = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto).setName("Project 2")); | |||
ComponentDto project3 = insertProjectAuthorizedToAnyone(newProjectDto(organizationDto).setName("Project 3")); | |||
associateProjectToQualitGate(project1.getId()); | |||
// Return partial result on first page |
@@ -48,7 +48,7 @@ public class QualityGateFinderTest { | |||
@Test | |||
public void return_default_quality_gate_for_project() { | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto()); | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization())); | |||
QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way"); | |||
Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, project.getId()); | |||
@@ -60,7 +60,7 @@ public class QualityGateFinderTest { | |||
@Test | |||
public void return_project_quality_gate_over_default() { | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto()); | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert())); | |||
dbTester.qualityGates().createDefaultQualityGate("Sonar way"); | |||
QualityGateDto dbQualityGate = dbTester.qualityGates().insertQualityGate("My team QG"); | |||
dbTester.qualityGates().associateProjectToQualityGate(project, dbQualityGate); | |||
@@ -74,7 +74,7 @@ public class QualityGateFinderTest { | |||
@Test | |||
public void return_nothing_when_no_default_qgate_and_no_qgate_defined_for_project() { | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto()); | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization())); | |||
Optional<QualityGateFinder.QualityGateData> result = underTest.getQualityGate(dbSession, project.getId()); | |||
@@ -83,7 +83,7 @@ public class QualityGateFinderTest { | |||
@Test | |||
public void fail_when_default_qgate_defined_in_properties_does_not_exists() throws Exception { | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto()); | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.organizations().insert())); | |||
QualityGateDto dbQualityGate = dbTester.qualityGates().createDefaultQualityGate("Sonar way"); | |||
dbTester.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession); | |||
@@ -93,7 +93,7 @@ public class QualityGateFinderTest { | |||
@Test | |||
public void fail_when_project_qgate_defined_in_properties_does_not_exists() throws Exception { | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto()); | |||
ComponentDto project = dbTester.components().insertComponent(newProjectDto(dbTester.getDefaultOrganization())); | |||
QualityGateDto dbQualityGate = dbTester.qualityGates().insertQualityGate("My team QG"); | |||
dbTester.qualityGates().associateProjectToQualityGate(project, dbQualityGate); | |||
dbTester.getDbClient().qualityGateDao().delete(dbQualityGate, dbSession); |
@@ -44,6 +44,7 @@ import org.sonar.core.util.Uuids; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.property.PropertiesDao; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.db.qualitygate.QualityGateConditionDao; | |||
@@ -104,7 +105,8 @@ public class QualityGatesTest { | |||
when(dbClient.propertiesDao()).thenReturn(propertiesDao); | |||
when(dbClient.componentDao()).thenReturn(componentDao); | |||
when(componentDao.selectOrFailById(eq(dbSession), anyLong())).thenReturn(newProjectDto(PROJECT_UUID).setId(1L).setKey(PROJECT_KEY)); | |||
when(componentDao.selectOrFailById(eq(dbSession), anyLong())).thenReturn( | |||
newProjectDto(OrganizationTesting.newOrganizationDto(), PROJECT_UUID).setId(1L).setKey(PROJECT_KEY)); | |||
underTest = new QualityGates(dbClient, metricFinder, userSessionRule); | |||
@@ -212,7 +212,7 @@ public class DeselectActionTest { | |||
} | |||
private ComponentDto insertProject() { | |||
return componentDb.insertComponent(newProjectDto()); | |||
return componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
} | |||
private QualityGateDto insertQualityGate() { |
@@ -34,6 +34,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.property.PropertyDto; | |||
import org.sonar.db.qualitygate.QualityGateDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
@@ -70,7 +71,8 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void json_example() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(organizationDto)); | |||
QualityGateDto qualityGate = insertQualityGate("My team QG"); | |||
associateProjectToQualityGate(project.getId(), qualityGate.getId()); | |||
@@ -83,7 +85,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void empty_response() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
insertQualityGate("Another QG"); | |||
String result = ws.newRequest().setParam(PARAM_PROJECT_ID, project.uuid()).execute().getInput(); | |||
@@ -93,7 +95,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void default_quality_gate() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); | |||
setDefaultQualityGate(dbQualityGate.getId()); | |||
@@ -107,7 +109,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void project_quality_gate_over_default() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
QualityGateDto defaultDbQualityGate = insertQualityGate("Sonar way"); | |||
QualityGateDto dbQualityGate = insertQualityGate("My team QG"); | |||
setDefaultQualityGate(defaultDbQualityGate.getId()); | |||
@@ -122,7 +124,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void get_by_project_key() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
QualityGateDto dbQualityGate = insertQualityGate("My team QG"); | |||
associateProjectToQualityGate(project.getId(), dbQualityGate.getId()); | |||
@@ -133,7 +135,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void get_with_project_admin_permission() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.USER, project.uuid()); | |||
QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); | |||
setDefaultQualityGate(dbQualityGate.getId()); | |||
@@ -145,7 +147,7 @@ public class GetByProjectActionTest { | |||
@Test | |||
public void get_with_project_browse_permission() { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, project.uuid()); | |||
QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); | |||
setDefaultQualityGate(dbQualityGate.getId()); | |||
@@ -159,7 +161,7 @@ public class GetByProjectActionTest { | |||
public void fail_when_insufficient_permission() { | |||
expectedException.expect(ForbiddenException.class); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
userSession.anonymous().setGlobalPermissions(GlobalPermissions.SCAN_EXECUTION); | |||
QualityGateDto dbQualityGate = insertQualityGate("Sonar way"); | |||
setDefaultQualityGate(dbQualityGate.getId()); |
@@ -85,7 +85,7 @@ public class ProjectStatusActionTest { | |||
public void json_example() throws IOException { | |||
userSession.setGlobalPermissions(SYSTEM_ADMIN); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project) | |||
.setPeriodMode(1, "last_period") | |||
.setPeriodDate(1, 956789123456L) | |||
@@ -114,7 +114,7 @@ public class ProjectStatusActionTest { | |||
public void return_status_by_project_id() throws IOException { | |||
userSession.setGlobalPermissions(SYSTEM_ADMIN); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project) | |||
.setPeriodMode(1, "last_period") | |||
.setPeriodDate(1, 956789123456L) | |||
@@ -143,7 +143,7 @@ public class ProjectStatusActionTest { | |||
public void return_status_by_project_key() throws IOException { | |||
userSession.setGlobalPermissions(SYSTEM_ADMIN); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid").setKey("project-key")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid").setKey("project-key")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project) | |||
.setPeriodMode(1, "last_period") | |||
.setPeriodDate(1, 956789123456L) | |||
@@ -172,7 +172,7 @@ public class ProjectStatusActionTest { | |||
public void return_undefined_status_if_measure_is_not_found() { | |||
userSession.setGlobalPermissions(SYSTEM_ADMIN); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); | |||
dbSession.commit(); | |||
@@ -185,7 +185,7 @@ public class ProjectStatusActionTest { | |||
@Test | |||
public void return_undefined_status_if_snapshot_is_not_found() { | |||
userSession.setGlobalPermissions(SYSTEM_ADMIN); | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
ProjectStatusWsResponse result = callByProjectUuid("project-uuid"); | |||
@@ -197,7 +197,7 @@ public class ProjectStatusActionTest { | |||
public void not_fail_with_project_admin_permission() { | |||
userSession.addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); | |||
dbSession.commit(); | |||
@@ -208,7 +208,7 @@ public class ProjectStatusActionTest { | |||
public void not_fail_with_browse_permission() { | |||
userSession.addProjectUuidPermissions(UserRole.USER, "project-uuid"); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); | |||
dbSession.commit(); | |||
@@ -229,7 +229,7 @@ public class ProjectStatusActionTest { | |||
public void fail_if_insufficient_privileges() { | |||
userSession.setGlobalPermissions(PROVISIONING); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
SnapshotDto snapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(project)); | |||
dbSession.commit(); | |||
@@ -41,7 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.core.permission.GlobalPermissions.QUALITY_GATE_ADMIN; | |||
import static org.sonar.core.permission.GlobalPermissions.QUALITY_PROFILE_ADMIN; | |||
import static org.sonar.core.permission.GlobalPermissions.SYSTEM_ADMIN; | |||
import static org.sonar.db.component.ComponentTesting.newProjectDto; | |||
import static org.sonar.server.qualitygate.QualityGates.SONAR_QUALITYGATE_PROPERTY; | |||
public class SelectActionTest { | |||
@@ -191,7 +190,7 @@ public class SelectActionTest { | |||
} | |||
private ComponentDto insertProject() { | |||
return componentDb.insertComponent(newProjectDto()); | |||
return componentDb.insertProject(db.organizations().insert()); | |||
} | |||
private QualityGateDto insertQualityGate() { |
@@ -30,6 +30,8 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.permission.UserPermissionDao; | |||
import org.sonar.db.permission.UserPermissionDto; | |||
import org.sonar.db.qualityprofile.QualityProfileDto; | |||
@@ -54,6 +56,7 @@ public class QProfileProjectOperationsMediumTest { | |||
DbSession dbSession; | |||
QProfileFactory factory; | |||
QProfileProjectOperations projectOperations; | |||
OrganizationDto organization; | |||
ComponentDto project; | |||
QualityProfileDto profile; | |||
static final String PROJECT_KEY = "SonarQube"; | |||
@@ -70,7 +73,9 @@ public class QProfileProjectOperationsMediumTest { | |||
factory = tester.get(QProfileFactory.class); | |||
projectOperations = tester.get(QProfileProjectOperations.class); | |||
project = ComponentTesting.newProjectDto(PROJECT_UUID) | |||
organization = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(dbSession, organization); | |||
project = ComponentTesting.newProjectDto(organization, PROJECT_UUID) | |||
.setKey(PROJECT_KEY) | |||
.setName("SonarQube") | |||
.setLongName("SonarQube"); | |||
@@ -121,11 +126,11 @@ public class QProfileProjectOperationsMediumTest { | |||
@Test | |||
public void remove_all_projects() { | |||
ComponentDto project1 = ComponentTesting.newProjectDto("BCDE") | |||
ComponentDto project1 = ComponentTesting.newProjectDto(organization, "BCDE") | |||
.setKey("project1") | |||
.setName("project1") | |||
.setLongName("project1"); | |||
ComponentDto project2 = ComponentTesting.newProjectDto("CDEF") | |||
ComponentDto project2 = ComponentTesting.newProjectDto(organization, "CDEF") | |||
.setKey("project2") | |||
.setName("project2") | |||
.setLongName("project2"); |
@@ -57,7 +57,7 @@ public class QProfilesTest { | |||
@Test | |||
public void findProfileByProjectAndLanguage() { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID); | |||
dbTester.getDbClient().componentDao().insert(dbTester.getSession(), project); | |||
QualityProfileDao qProfileDao = dbTester.getDbClient().qualityProfileDao(); | |||
QualityProfileDto profile = QualityProfileTesting.newQualityProfileDto().setLanguage("js"); |
@@ -84,7 +84,7 @@ public class AddProjectActionTest { | |||
@Before | |||
public void setUp() throws Exception { | |||
project = componentDb.insertComponent(ComponentTesting.newProjectDto()); | |||
project = componentDb.insertComponent(ComponentTesting.newProjectDto(dbTester.organizations().insert())); | |||
} | |||
@Test |
@@ -86,7 +86,7 @@ public class DeleteActionTest { | |||
public void delete_nominal_with_key() throws Exception { | |||
String profileKey = "sonar-way-xoo1-12345"; | |||
ComponentDto project = ComponentTesting.newProjectDto("polop"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "polop"); | |||
componentDao.insert(session, project); | |||
qualityProfileDao.insert(session, QualityProfileDto.createFor(profileKey).setLanguage(xoo1.getKey()).setName("Sonar way")); | |||
qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session); | |||
@@ -104,7 +104,7 @@ public class DeleteActionTest { | |||
public void delete_nominal_with_language_and_name() throws Exception { | |||
String profileKey = "sonar-way-xoo1-12345"; | |||
ComponentDto project = ComponentTesting.newProjectDto("polop"); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), "polop"); | |||
componentDao.insert(session, project); | |||
qualityProfileDao.insert(session, QualityProfileDto.createFor(profileKey).setLanguage(xoo1.getKey()).setName("Sonar way")); | |||
qualityProfileDao.insertProjectProfileAssociation(project.uuid(), profileKey, session); |
@@ -208,7 +208,7 @@ public class ProjectsActionTest { | |||
} | |||
private ComponentDto newProject(String uuid, String name) { | |||
return ComponentTesting.newProjectDto(uuid).setName(name); | |||
return ComponentTesting.newProjectDto(db.organizations().insert(), uuid).setName(name); | |||
} | |||
private void addBrowsePermissionToAnyone(ComponentDto... projects) { |
@@ -35,6 +35,8 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.db.qualityprofile.ActiveRuleDao; | |||
import org.sonar.db.qualityprofile.ActiveRuleDto; | |||
import org.sonar.db.qualityprofile.ActiveRuleKey; | |||
@@ -440,7 +442,9 @@ public class QProfilesWsMediumTest { | |||
@Test | |||
public void add_project_with_key_and_uuid() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setId(1L); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(session, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L); | |||
db.componentDao().insert(session, project); | |||
QualityProfileDto profile = QProfileTesting.newXooP1(); | |||
db.qualityProfileDao().insert(session, profile); | |||
@@ -461,7 +465,9 @@ public class QProfilesWsMediumTest { | |||
@Test | |||
public void change_project_association_with_key_and_uuid() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setId(1L); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(session, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L); | |||
db.componentDao().insert(session, project); | |||
QualityProfileDto profile1 = QProfileTesting.newXooP1(); | |||
QualityProfileDto profile2 = QProfileTesting.newXooP2(); | |||
@@ -478,7 +484,9 @@ public class QProfilesWsMediumTest { | |||
@Test | |||
public void add_project_with_name_language_and_key() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setId(1L); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(session, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L); | |||
db.componentDao().insert(session, project); | |||
QualityProfileDto profile = QProfileTesting.newXooP1(); | |||
db.qualityProfileDao().insert(session, profile); | |||
@@ -535,7 +543,9 @@ public class QProfilesWsMediumTest { | |||
@Test | |||
public void remove_project_with_key_and_uuid() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setId(1L); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(session, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L); | |||
db.componentDao().insert(session, project); | |||
QualityProfileDto profile = QProfileTesting.newXooP1(); | |||
db.qualityProfileDao().insert(session, profile); | |||
@@ -551,7 +561,9 @@ public class QProfilesWsMediumTest { | |||
@Test | |||
public void remove_project_with_name_language_and_key() throws Exception { | |||
ComponentDto project = ComponentTesting.newProjectDto("ABCD").setId(1L); | |||
OrganizationDto organizationDto = OrganizationTesting.newOrganizationDto(); | |||
db.organizationDao().insert(session, organizationDto); | |||
ComponentDto project = ComponentTesting.newProjectDto(organizationDto, "ABCD").setId(1L); | |||
db.componentDao().insert(session, project); | |||
QualityProfileDto profile = QProfileTesting.newXooP1(); | |||
db.qualityProfileDao().insert(session, profile); |
@@ -36,6 +36,7 @@ import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.db.qualityprofile.QualityProfileDao; | |||
import org.sonar.db.qualityprofile.QualityProfileDbTester; | |||
import org.sonar.db.qualityprofile.QualityProfileDto; | |||
@@ -106,14 +107,15 @@ public class SearchActionTest { | |||
"sonar-way-xoo1-12345", 1L, | |||
"my-sonar-way-xoo2-34567", 2L)); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
qualityProfileDao.insert(dbSession, | |||
QualityProfileDto.createFor("sonar-way-xoo1-12345").setLanguage(xoo1.getKey()).setName("Sonar way").setDefault(true), | |||
QualityProfileDto.createFor("sonar-way-xoo2-23456").setLanguage(xoo2.getKey()).setName("Sonar way"), | |||
QualityProfileDto.createFor("my-sonar-way-xoo2-34567").setLanguage(xoo2.getKey()).setName("My Sonar way").setParentKee("sonar-way-xoo2-23456"), | |||
QualityProfileDto.createFor("sonar-way-other-666").setLanguage("other").setName("Sonar way").setDefault(true)); | |||
new ComponentDao().insert(dbSession, | |||
newProjectDto("project-uuid1"), | |||
newProjectDto("project-uuid2")); | |||
newProjectDto(organizationDto, "project-uuid1"), | |||
newProjectDto(organizationDto, "project-uuid2")); | |||
qualityProfileDao.insertProjectProfileAssociation("project-uuid1", "sonar-way-xoo2-23456", dbSession); | |||
qualityProfileDao.insertProjectProfileAssociation("project-uuid2", "sonar-way-xoo2-23456", dbSession); | |||
db.commit(); | |||
@@ -167,7 +169,7 @@ public class SearchActionTest { | |||
.setRulesUpdatedAt("2016-12-21T19:10:03+0100") | |||
.setLastUsed(time) | |||
.setName("Another way"); | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1); | |||
qualityProfileDb.insertProjectWithQualityProfileAssociations(project, qualityProfileOnXoo1, qualityProfileOnXoo2); | |||
@@ -224,7 +226,7 @@ public class SearchActionTest { | |||
.setRulesUpdatedAtAsDate(new Date()) | |||
.setName("Another way"); | |||
qualityProfileDb.insertQualityProfiles(qualityProfileOnXoo1, qualityProfileOnXoo2, anotherQualityProfileOnXoo1); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto("project-uuid")); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.organizations().insert(), "project-uuid")); | |||
String result = ws.newRequest() | |||
.setParam(PARAM_PROJECT_KEY, project.key()) |
@@ -93,7 +93,7 @@ public class ListDefinitionsActionTest { | |||
@Before | |||
public void setUp() throws Exception { | |||
project = componentDb.insertComponent(newProjectDto()); | |||
project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
} | |||
@Test |
@@ -90,7 +90,7 @@ public class ResetActionTest { | |||
@Before | |||
public void setUp() throws Exception { | |||
project = componentDb.insertComponent(newProjectDto()); | |||
project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
} | |||
@Test |
@@ -530,7 +530,7 @@ public class SetActionTest { | |||
.defaultValue("default") | |||
.onQualifiers(Qualifiers.PROJECT) | |||
.build()); | |||
ComponentDto view = db.components().insertComponent(newView("view-uuid")); | |||
ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid")); | |||
i18n.put("qualifier." + Qualifiers.VIEW, "View"); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("Setting 'my.key' cannot be set on a View"); |
@@ -67,7 +67,7 @@ public class SettingsUpdaterTest { | |||
@Before | |||
public void setUp() throws Exception { | |||
project = componentDb.insertComponent(newProjectDto()); | |||
project = componentDb.insertComponent(newProjectDto(db.organizations().insert())); | |||
} | |||
@Test |
@@ -32,6 +32,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
@@ -63,7 +64,7 @@ public class IndexActionTest { | |||
WsTester tester; | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
@Before |
@@ -236,7 +236,7 @@ public class LinesActionTest { | |||
} | |||
private void insertFile() throws IOException { | |||
ComponentDto project = ComponentTesting.newProjectDto(PROJECT_UUID); | |||
ComponentDto project = ComponentTesting.newProjectDto(dbTester.organizations().insert(), PROJECT_UUID); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null, FILE_UUID).setKey(FILE_KEY); | |||
componentDao.insert(dbTester.getSession(), project, file); | |||
dbTester.getSession().commit(); |
@@ -32,6 +32,7 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.component.ComponentDao; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.organization.OrganizationTesting; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.source.SourceService; | |||
@@ -62,7 +63,7 @@ public class RawActionTest { | |||
WsTester tester; | |||
ComponentDto project = ComponentTesting.newProjectDto(); | |||
ComponentDto project = ComponentTesting.newProjectDto(OrganizationTesting.newOrganizationDto()); | |||
ComponentDto file = ComponentTesting.newFileDto(project, null); | |||
@Before |