by joining on ORGANIZATIONS table add organizationKey (read-only) to ComponentDtotags/6.3-RC1
@@ -113,7 +113,7 @@ public class CeQueueImplTest { | |||
@Test | |||
public void massSubmit_populates_component_name_and_key_of_CeTask_if_component_exists() { | |||
ComponentDto componentDto1 = insertComponent(ComponentTesting.newProjectDto("PROJECT_1")); | |||
ComponentDto componentDto1 = insertComponent(ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), "PROJECT_1")); | |||
CeTaskSubmit taskSubmit1 = createTaskSubmit(CeTaskTypes.REPORT, componentDto1.uuid(), null); | |||
CeTaskSubmit taskSubmit2 = createTaskSubmit("something", "non existing component uuid", null); | |||
@@ -42,6 +42,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.server.component.es.ProjectMeasuresDoc; | |||
import org.sonar.server.component.es.ProjectMeasuresIndex; | |||
@@ -79,15 +80,13 @@ import static org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FIL | |||
public class SearchProjectsActionTest { | |||
private static final String NCLOC = "ncloc"; | |||
private static final String COVERAGE = "coverage"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone().login().setUserId(23); | |||
@Rule | |||
public EsTester es = new EsTester(new ProjectMeasuresIndexDefinition(new MapSettings())); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
@@ -106,15 +105,17 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void json_example() { | |||
long project1Id = insertProjectInDbAndEs(newProjectDto() | |||
OrganizationDto organization1Dto = db.organizations().insertForKey("my-org-key-1"); | |||
OrganizationDto organization2Dto = db.organizations().insertForKey("my-org-key-2"); | |||
long project1Id = insertProjectInDbAndEs(newProjectDto(organization1Dto) | |||
.setUuid(Uuids.UUID_EXAMPLE_01) | |||
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_001) | |||
.setName("My Project 1")); | |||
insertProjectInDbAndEs(newProjectDto() | |||
insertProjectInDbAndEs(newProjectDto(organization1Dto) | |||
.setUuid(Uuids.UUID_EXAMPLE_02) | |||
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_002) | |||
.setName("My Project 2")); | |||
insertProjectInDbAndEs(newProjectDto() | |||
insertProjectInDbAndEs(newProjectDto(organization2Dto) | |||
.setUuid(Uuids.UUID_EXAMPLE_03) | |||
.setKey(KeyExamples.KEY_PROJECT_EXAMPLE_003) | |||
.setName("My Project 3")); | |||
@@ -129,9 +130,9 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void order_by_name_case_insensitive() { | |||
insertProjectInDbAndEs(newProjectDto().setName("Maven")); | |||
insertProjectInDbAndEs(newProjectDto().setName("Apache")); | |||
insertProjectInDbAndEs(newProjectDto().setName("guava")); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Maven")); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Apache")); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("guava")); | |||
SearchProjectsWsResponse result = call(request); | |||
@@ -141,7 +142,7 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void paginate_result() { | |||
IntStream.rangeClosed(1, 9).forEach(i -> insertProjectInDbAndEs(newProjectDto().setName("PROJECT-" + i))); | |||
IntStream.rangeClosed(1, 9).forEach(i -> insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("PROJECT-" + i))); | |||
SearchProjectsWsResponse result = call(request.setPage(2).setPageSize(3)); | |||
@@ -167,7 +168,8 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void return_only_projects() { | |||
ComponentDto project = newProjectDto().setName("SonarQube"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
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)); | |||
@@ -180,9 +182,10 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void filter_projects_with_query() { | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d))); | |||
OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1"); | |||
insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_001d))); | |||
insertMetrics(COVERAGE, NCLOC); | |||
request.setFilter("coverage <= 80 and ncloc <= 10000"); | |||
@@ -194,8 +197,8 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void filter_projects_on_favorites() { | |||
long javaId = insertProjectInDbAndEs(newProjectDto("java-id").setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 10_000d))); | |||
long markDownId = insertProjectInDbAndEs(newProjectDto("markdown-id").setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
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))); | |||
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()))); | |||
@@ -210,7 +213,7 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void do_not_return_isFavorite_if_anonymous_user() { | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81))); | |||
insertMetrics(COVERAGE); | |||
userSession.anonymous(); | |||
@@ -222,7 +225,7 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void empty_list_if_isFavorite_filter_and_anonymous_user() { | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81))); | |||
insertMetrics(COVERAGE); | |||
userSession.anonymous(); | |||
request.setFilter("isFavorite"); | |||
@@ -234,10 +237,10 @@ public class SearchProjectsActionTest { | |||
@Test | |||
public void return_nloc_facet() { | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto().setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d))); | |||
insertProjectInDbAndEs(newProjectDto(db.getDefaultOrganization()).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d))); | |||
insertMetrics(COVERAGE, NCLOC); | |||
SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC))); | |||
@@ -59,9 +59,10 @@ public class ShowActionTest { | |||
.setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
ComponentDbTester componentDb = new ComponentDbTester(db); | |||
WsActionTester ws = new WsActionTester(new ShowAction(userSession, db.getDbClient(), new ComponentFinder(db.getDbClient()))); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private WsActionTester ws = new WsActionTester(new ShowAction(userSession, db.getDbClient(), new ComponentFinder(db.getDbClient()))); | |||
@Test | |||
public void json_example() throws IOException { | |||
@@ -141,7 +142,7 @@ public class ShowActionTest { | |||
} | |||
private void insertJsonExampleComponentsAndSnapshots() { | |||
ComponentDto project = newProjectDto("AVIF98jgA3Ax6PH2efOW") | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "AVIF98jgA3Ax6PH2efOW") | |||
.setKey("com.sonarsource:java-markdown") | |||
.setName("Java Markdown") | |||
.setDescription("Java Markdown Project") |
@@ -48,6 +48,7 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.ResourceTypesRule; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.BadRequestException; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
@@ -77,9 +78,10 @@ public class TreeActionTest { | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
ResourceTypesRule resourceTypes = new ResourceTypesRule(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
ResourceTypesRule resourceTypes = new ResourceTypesRule(); | |||
ComponentDbTester componentDb = new ComponentDbTester(db); | |||
DbClient dbClient = db.getDbClient(); | |||
@@ -230,9 +232,10 @@ public class TreeActionTest { | |||
@Test | |||
public void return_children_of_a_view() { | |||
ComponentDto view = newView("view-uuid"); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
ComponentDto view = newView(organizationDto, "view-uuid"); | |||
componentDb.insertViewAndSnapshot(view); | |||
ComponentDto project = newProjectDto("project-uuid-1").setName("project-name").setKey("project-key-1"); | |||
ComponentDto project = newProjectDto(organizationDto, "project-uuid-1").setName("project-name").setKey("project-key-1"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
componentDb.insertComponent(newProjectCopy("project-uuid-1-copy", project, view)); | |||
componentDb.insertComponent(newSubView(view, "sub-view-uuid", "sub-view-key").setName("sub-view-name")); | |||
@@ -251,7 +254,7 @@ public class TreeActionTest { | |||
@Test | |||
public void response_is_empty_on_provisioned_projects() { | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
TreeWsResponse response = call(ws.newRequest() | |||
.setParam(PARAM_BASE_COMPONENT_ID, "project-uuid")); | |||
@@ -265,9 +268,9 @@ public class TreeActionTest { | |||
@Test | |||
public void return_developers() { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto developer = newDeveloper("developer-name"); | |||
ComponentDto developer = newDeveloper(db.organizations().insert(), "developer-name"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
componentDb.insertComponent(newDevProjectCopy("project-copy-uuid", project, developer)); | |||
db.commit(); | |||
@@ -282,7 +285,7 @@ public class TreeActionTest { | |||
@Test | |||
public void return_projects_composing_a_view() { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.organizations().insert(), "project-uuid"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto view = newView("view-uuid"); | |||
componentDb.insertViewAndSnapshot(view); |
@@ -340,8 +340,8 @@ public class InternalCeQueueImplTest { | |||
assertThat(queueDto.get().getCreatedAt()).isEqualTo(1_450_000_000_000L); | |||
} | |||
private static ComponentDto newComponentDto(String uuid) { | |||
return ComponentTesting.newProjectDto(uuid).setName("name_" + uuid).setKey("key_" + uuid); | |||
private ComponentDto newComponentDto(String uuid) { | |||
return ComponentTesting.newProjectDto(dbTester.getDefaultOrganization(), uuid).setName("name_" + uuid).setKey("key_" + uuid); | |||
} | |||
private CeTask submit(String reportType, String componentUuid) { |
@@ -94,13 +94,10 @@ public class BulkChangeActionTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
@Rule | |||
public EsTester es = new EsTester(new IssueIndexDefinition(new MapSettings())); | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@@ -123,7 +120,7 @@ public class BulkChangeActionTest { | |||
public void setUp() throws Exception { | |||
issueWorkflow.start(); | |||
rule = db.rules().insertRule(newRuleDto()); | |||
project = db.components().insertProject(); | |||
project = db.components().insertProject(db.organizations().insert()); | |||
file = db.components().insertComponent(newFileDto(project)); | |||
user = db.users().insertUser("john"); | |||
when(system2.now()).thenReturn(NOW); |
@@ -89,7 +89,7 @@ public class ChangelogActionTest { | |||
@Test | |||
public void changelog_of_file_move_contains_file_names() throws Exception { | |||
RuleDto rule = db.rules().insertRule(newRuleDto()); | |||
ComponentDto project = db.components().insertProject(); | |||
ComponentDto project = db.components().insertProject(db.organizations().insert()); | |||
ComponentDto file1 = db.components().insertComponent(newFileDto(project)); | |||
ComponentDto file2 = db.components().insertComponent(newFileDto(project)); | |||
IssueDto issueDto = db.issues().insertIssue(newDto(rule, file2, project)); |
@@ -38,10 +38,15 @@ import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
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; | |||
import org.sonar.server.issue.index.IssueIndexer; | |||
import org.sonar.server.organization.DefaultOrganization; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.permission.GroupPermissionChange; | |||
import org.sonar.server.permission.PermissionChange; | |||
import org.sonar.server.permission.PermissionUpdater; | |||
@@ -80,9 +85,12 @@ public class SearchActionComponentsMediumTest { | |||
@Rule | |||
public UserSessionRule userSessionRule = UserSessionRule.forServerTester(tester); | |||
DbClient db; | |||
DbSession session; | |||
WsTester wsTester; | |||
private DbClient db; | |||
private DbSession session; | |||
private WsTester wsTester; | |||
private OrganizationDto defaultOrganization; | |||
private OrganizationDto otherOrganization1; | |||
private OrganizationDto otherOrganization2; | |||
@Before | |||
public void setUp() { | |||
@@ -90,6 +98,14 @@ public class SearchActionComponentsMediumTest { | |||
db = tester.get(DbClient.class); | |||
wsTester = tester.get(WsTester.class); | |||
session = db.openSession(false); | |||
OrganizationDao organizationDao = db.organizationDao(); | |||
DefaultOrganization defaultOrganization = tester.get(DefaultOrganizationProvider.class).get(); | |||
this.defaultOrganization = organizationDao.selectByUuid(session, defaultOrganization.getUuid()).get(); | |||
this.otherOrganization1 = OrganizationTesting.newOrganizationDto().setKey("my-org-1"); | |||
this.otherOrganization2 = OrganizationTesting.newOrganizationDto().setKey("my-org-2"); | |||
organizationDao.insert(session, this.otherOrganization1); | |||
organizationDao.insert(session, this.otherOrganization2); | |||
session.commit(); | |||
} | |||
@After | |||
@@ -100,7 +116,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void issues_on_different_projects() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
IssueDto issue = IssueTesting.newDto(rule, file, project) | |||
@@ -111,7 +127,7 @@ public class SearchActionComponentsMediumTest { | |||
.setIssueUpdateDate(DateUtils.parseDateTime("2017-12-04T00:00:00+0100")); | |||
db.issueDao().insert(session, issue); | |||
ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto("P2").setKey("PK2")); | |||
ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P2").setKey("PK2")); | |||
setDefaultProjectPermission(project2); | |||
ComponentDto file2 = insertComponent(newFileDto(project2, null, "F2").setKey("FK2")); | |||
IssueDto issue2 = IssueTesting.newDto(rule, file2, project2) | |||
@@ -130,7 +146,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void do_not_return_module_key_on_single_module_projects() throws IOException { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto module = insertComponent(newModuleDto("M1", project).setKey("MK1")); | |||
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setKey("FK1")); | |||
@@ -160,7 +176,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_project_uuid() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); | |||
@@ -191,7 +207,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_since_leak_period_on_project() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
db.snapshotDao().insert(session, | |||
@@ -219,7 +235,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_since_leak_period_on_file_in_module_project() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto module = insertComponent(newModuleDto(project)); | |||
ComponentDto file = insertComponent(newFileDto(module, null, "F1").setKey("FK1")); | |||
@@ -248,9 +264,9 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void project_facet_is_sticky() throws Exception { | |||
ComponentDto project1 = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto("P2").setKey("PK2")); | |||
ComponentDto project3 = insertComponent(ComponentTesting.newProjectDto("P3").setKey("PK3")); | |||
ComponentDto project1 = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
ComponentDto project2 = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P2").setKey("PK2")); | |||
ComponentDto project3 = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P3").setKey("PK3")); | |||
setDefaultProjectPermission(project1); | |||
setDefaultProjectPermission(project2); | |||
setDefaultProjectPermission(project3); | |||
@@ -274,7 +290,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_file_uuid() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2"); | |||
@@ -305,7 +321,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_file_key() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
ComponentDto unitTest = insertComponent(newFileDto(project, null, "F2").setQualifier(Qualifiers.UNIT_TEST_FILE).setKey("FK2")); | |||
@@ -329,7 +345,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void display_file_facet() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file1 = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
ComponentDto file2 = insertComponent(newFileDto(project, null, "F2").setKey("FK2")); | |||
@@ -351,7 +367,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_directory_path() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir")); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java")); | |||
@@ -383,7 +399,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_directory_path_in_different_modules() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto module1 = insertComponent(newModuleDto("M1", project).setKey("MK1")); | |||
ComponentDto module2 = insertComponent(newModuleDto("M2", project).setKey("MK2")); | |||
@@ -433,7 +449,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void display_module_facet() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto module = insertComponent(newModuleDto("M1", project).setKey("MK1")); | |||
ComponentDto subModule1 = insertComponent(newModuleDto("SUBM1", module).setKey("SUBMK1")); | |||
@@ -458,7 +474,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void display_directory_facet() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto directory = insertComponent(ComponentTesting.newDirectory(project, "D1", "src/main/java/dir")); | |||
ComponentDto file = insertComponent(newFileDto(project, directory, "F1").setKey("FK1").setPath(directory.path() + "/MyComponent.java")); | |||
@@ -477,12 +493,12 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_view_uuid() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto("V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
indexView(view.uuid(), newArrayList(project.uuid())); | |||
setAnyoneProjectPermission(view, UserRole.USER); | |||
@@ -496,12 +512,12 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_view_uuid_return_only_authorized_view() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto("V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
indexView(view.uuid(), newArrayList(project.uuid())); | |||
setAnyoneProjectPermission(view, UserRole.USER); | |||
@@ -516,14 +532,14 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_sub_view_uuid() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto("V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
indexView(view.uuid(), newArrayList(project.uuid())); | |||
ComponentDto subView = insertComponent(ComponentTesting.newProjectDto("SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView")); | |||
ComponentDto subView = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView")); | |||
indexView(subView.uuid(), newArrayList(project.uuid())); | |||
setAnyoneProjectPermission(view, UserRole.USER); | |||
@@ -537,14 +553,14 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_sub_view_uuid_return_only_authorized_view() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
insertIssue(IssueTesting.newDto(newRule(), file, project).setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto("V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
ComponentDto view = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "V1").setQualifier(Qualifiers.VIEW).setKey("MyView")); | |||
indexView(view.uuid(), newArrayList(project.uuid())); | |||
ComponentDto subView = insertComponent(ComponentTesting.newProjectDto("SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView")); | |||
ComponentDto subView = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "SV1").setQualifier(Qualifiers.SUBVIEW).setKey("MySubView")); | |||
indexView(subView.uuid(), newArrayList(project.uuid())); | |||
setAnyoneProjectPermission(view, UserRole.USER); | |||
@@ -559,7 +575,7 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_author() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
RuleDto newRule = newRule(); | |||
@@ -585,10 +601,10 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_developer() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
ComponentDto developer = insertComponent(ComponentTesting.newDeveloper("Anakin Skywalker")); | |||
ComponentDto developer = insertComponent(ComponentTesting.newDeveloper(otherOrganization1, "Anakin Skywalker")); | |||
db.authorDao().insertAuthor(session, "vader", developer.getId()); | |||
db.authorDao().insertAuthor(session, "anakin@skywalker.name", developer.getId()); | |||
RuleDto newRule = newRule(); | |||
@@ -607,15 +623,15 @@ public class SearchActionComponentsMediumTest { | |||
@Test | |||
public void search_by_developer_technical_project() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("P1").setKey("PK1")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "P1").setKey("PK1")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(newFileDto(project, null, "F1").setKey("FK1")); | |||
ComponentDto otherProject = insertComponent(ComponentTesting.newProjectDto("P2").setKey("PK2")); | |||
ComponentDto otherProject = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "P2").setKey("PK2")); | |||
setDefaultProjectPermission(otherProject); | |||
ComponentDto otherFile = insertComponent(newFileDto(otherProject, null, "F2").setKey("FK2")); | |||
ComponentDto developer = insertComponent(ComponentTesting.newDeveloper("Anakin Skywalker")); | |||
ComponentDto developer = insertComponent(ComponentTesting.newDeveloper(defaultOrganization, "Anakin Skywalker")); | |||
ComponentDto technicalProject = insertComponent(ComponentTesting.newDevProjectCopy("COPY_P1", project, developer)); | |||
insertComponent(ComponentTesting.newDevProjectCopy("COPY_P2", otherProject, developer)); | |||
@@ -42,12 +42,17 @@ import org.sonar.db.issue.IssueChangeDto; | |||
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; | |||
import org.sonar.db.user.UserDto; | |||
import org.sonar.server.issue.IssueQuery; | |||
import org.sonar.server.issue.index.IssueIndexer; | |||
import org.sonar.server.organization.DefaultOrganization; | |||
import org.sonar.server.organization.DefaultOrganizationProvider; | |||
import org.sonar.server.permission.GroupPermissionChange; | |||
import org.sonar.server.permission.PermissionChange; | |||
import org.sonar.server.permission.PermissionUpdater; | |||
@@ -83,9 +88,12 @@ public class SearchActionMediumTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
DbClient db; | |||
DbSession session; | |||
WsTester wsTester; | |||
private DbClient db; | |||
private DbSession session; | |||
private WsTester wsTester; | |||
private OrganizationDto defaultOrganization; | |||
private OrganizationDto otherOrganization1; | |||
private OrganizationDto otherOrganization2; | |||
@Before | |||
public void setUp() { | |||
@@ -93,6 +101,14 @@ public class SearchActionMediumTest { | |||
db = tester.get(DbClient.class); | |||
wsTester = tester.get(WsTester.class); | |||
session = db.openSession(false); | |||
OrganizationDao organizationDao = db.organizationDao(); | |||
DefaultOrganization defaultOrganization = tester.get(DefaultOrganizationProvider.class).get(); | |||
this.defaultOrganization = organizationDao.selectByUuid(session, defaultOrganization.getUuid()).get(); | |||
this.otherOrganization1 = OrganizationTesting.newOrganizationDto().setKey("my-org-1"); | |||
this.otherOrganization2 = OrganizationTesting.newOrganizationDto().setKey("my-org-2"); | |||
organizationDao.insert(session, this.otherOrganization1); | |||
organizationDao.insert(session, this.otherOrganization2); | |||
session.commit(); | |||
} | |||
@After | |||
@@ -128,7 +144,7 @@ public class SearchActionMediumTest { | |||
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com")); | |||
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -156,7 +172,7 @@ public class SearchActionMediumTest { | |||
db.userDao().insert(session, new UserDto().setLogin("john").setName("John")); | |||
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -192,7 +208,7 @@ public class SearchActionMediumTest { | |||
db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com")); | |||
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -226,7 +242,7 @@ public class SearchActionMediumTest { | |||
public void load_additional_fields() throws Exception { | |||
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com")); | |||
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js")); | |||
setProjectPermission(project, USER); | |||
@@ -247,7 +263,7 @@ public class SearchActionMediumTest { | |||
public void load_additional_fields_with_issue_admin_permission() throws Exception { | |||
db.userDao().insert(session, new UserDto().setLogin("simon").setName("Simon").setEmail("simon@email.com")); | |||
db.userDao().insert(session, new UserDto().setLogin("fabrice").setName("Fabrice").setEmail("fabrice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY").setLanguage("java")); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY").setLanguage("js")); | |||
setProjectPermission(project, USER, ISSUE_ADMIN); | |||
@@ -267,7 +283,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void issue_on_removed_file() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto removedFile = insertComponent(ComponentTesting.newFileDto(project, null).setUuid("REMOVED_FILE_ID") | |||
.setKey("REMOVED_FILE_KEY") | |||
@@ -291,7 +307,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void issue_contains_component_id_for_eclipse() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project); | |||
@@ -306,7 +322,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void apply_paging_with_one_component() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
for (int i = 0; i < QueryContext.MAX_LIMIT + 1; i++) { | |||
@@ -322,7 +338,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void components_contains_sub_projects() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("ProjectHavingModule")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("ProjectHavingModule")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto module = insertComponent(ComponentTesting.newModuleDto(project).setKey("ModuleHavingFile")); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(module, null, "BCDE").setKey("FileLinkedToModule")); | |||
@@ -337,7 +353,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void display_facets() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -361,7 +377,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void display_facets_in_effort_mode() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -386,7 +402,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void display_zero_valued_facets_for_selected_items() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) | |||
@@ -427,7 +443,7 @@ public class SearchActionMediumTest { | |||
public void filter_by_assigned_to_me() throws Exception { | |||
db.userDao().insert(session, new UserDto().setLogin("john").setName("John").setEmail("john@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
RuleDto rule = newRule(); | |||
@@ -471,7 +487,7 @@ public class SearchActionMediumTest { | |||
public void filter_by_assigned_to_me_unauthenticated() throws Exception { | |||
userSessionRule.login(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
RuleDto rule = newRule(); | |||
@@ -501,7 +517,7 @@ public class SearchActionMediumTest { | |||
public void assigned_to_me_facet_is_sticky_relative_to_assignees() throws Exception { | |||
db.userDao().insert(session, new UserDto().setLogin("alice").setName("Alice").setEmail("alice@email.com")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
RuleDto rule = newRule(); | |||
@@ -544,7 +560,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void sort_by_updated_at() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
db.issueDao().insert(session, IssueTesting.newDto(rule, file, project) | |||
@@ -569,7 +585,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void paging() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
for (int i = 0; i < 12; i++) { | |||
@@ -590,7 +606,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void paging_with_page_size_to_minus_one() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization2, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
for (int i = 0; i < 12; i++) { | |||
@@ -611,7 +627,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void deprecated_paging() throws Exception { | |||
RuleDto rule = newRule(); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(defaultOrganization, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
for (int i = 0; i < 12; i++) { | |||
@@ -639,7 +655,7 @@ public class SearchActionMediumTest { | |||
@Test | |||
public void display_deprecated_debt_fields() throws Exception { | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto("PROJECT_ID").setKey("PROJECT_KEY")); | |||
ComponentDto project = insertComponent(ComponentTesting.newProjectDto(otherOrganization1, "PROJECT_ID").setKey("PROJECT_KEY")); | |||
setDefaultProjectPermission(project); | |||
ComponentDto file = insertComponent(ComponentTesting.newFileDto(project, null, "FILE_ID").setKey("FILE_KEY")); | |||
IssueDto issue = IssueTesting.newDto(newRule(), file, project) |
@@ -90,16 +90,16 @@ public class ComponentTreeActionTest { | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
I18nRule i18n = new I18nRule(); | |||
ResourceTypesRule resourceTypes = new ResourceTypesRule(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
ComponentDbTester componentDb = new ComponentDbTester(db); | |||
DbClient dbClient = db.getDbClient(); | |||
final DbSession dbSession = db.getSession(); | |||
WsActionTester ws = new WsActionTester( | |||
private I18nRule i18n = new I18nRule(); | |||
private ResourceTypesRule resourceTypes = new ResourceTypesRule(); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private DbClient dbClient = db.getDbClient(); | |||
private DbSession dbSession = db.getSession(); | |||
private WsActionTester ws = new WsActionTester( | |||
new ComponentTreeAction( | |||
new ComponentTreeDataLoader(dbClient, new ComponentFinder(dbClient), userSession, resourceTypes), | |||
i18n, resourceTypes)); | |||
@@ -127,7 +127,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void empty_response() { | |||
componentDb.insertComponent(newProjectDto("project-uuid")); | |||
componentDb.insertComponent(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
ComponentTreeWsResponse response = call(ws.newRequest() | |||
.setParam(PARAM_BASE_COMPONENT_ID, "project-uuid") | |||
@@ -141,7 +141,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_measures_and_periods() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
componentDb.insertComponent(projectDto); | |||
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, | |||
newAnalysis(projectDto) | |||
@@ -177,7 +177,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_measures_with_best_value() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
ComponentDto directoryDto = newDirectory(projectDto, "directory-uuid", "path/to/directory").setName("directory-1"); | |||
@@ -221,7 +221,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void use_best_value_for_rating() { | |||
userSession.anonymous().addProjectUuidPermissions(UserRole.ADMIN, "project-uuid"); | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
componentDb.insertComponent(projectDto); | |||
SnapshotDto projectSnapshot = dbClient.snapshotDao().insert(dbSession, newAnalysis(projectDto) | |||
.setPeriodDate(1, parseDateTime("2016-01-11T10:49:50+0100").getTime()) | |||
@@ -252,7 +252,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_measures_multi_sort_with_metric_key_and_paginated() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); | |||
ComponentDto file9 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-9").setName("file-1")); | |||
ComponentDto file8 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-8").setName("file-1")); | |||
@@ -294,7 +294,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void sort_by_metric_value() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); | |||
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4")); | |||
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3")); | |||
@@ -320,7 +320,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void remove_components_without_measure_on_the_metric_sort() { | |||
ComponentDto project = newProjectDto("project-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file1 = newFileDto(project, null, "file-uuid-1"); | |||
ComponentDto file2 = newFileDto(project, null, "file-uuid-2"); | |||
@@ -355,7 +355,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void sort_by_metric_period() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); | |||
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3")); | |||
ComponentDto file1 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-1")); | |||
@@ -380,7 +380,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void remove_components_without_measure_on_the_metric_period_sort() { | |||
ComponentDto projectDto = newProjectDto("project-uuid"); | |||
ComponentDto projectDto = newProjectDto(db.getDefaultOrganization(), "project-uuid"); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(projectDto); | |||
ComponentDto file4 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-4")); | |||
ComponentDto file3 = componentDb.insertComponent(newFileDto(projectDto, null, "file-uuid-3")); | |||
@@ -413,9 +413,9 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_developer_descendants() { | |||
ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key"); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto developer = newDeveloper("developer", "developer-uuid"); | |||
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
componentDb.insertComponent(newDevProjectCopy("project-uuid-copy", project, developer)); | |||
insertNclocMetric(); | |||
@@ -434,8 +434,8 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_developer_measures_by_developer_uuid() { | |||
ComponentDto developer = newDeveloper("developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); | |||
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid")); | |||
@@ -467,8 +467,8 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void load_developer_measures_by_developer_key() { | |||
ComponentDto developer = newDeveloper("developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); | |||
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid")); | |||
@@ -496,7 +496,7 @@ public class ComponentTreeActionTest { | |||
public void load_measures_when_no_leave_qualifier() { | |||
resourceTypes.setLeavesQualifiers(); | |||
String projectUuid = "project-uuid"; | |||
ComponentDto project = newProjectDto(projectUuid); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), projectUuid); | |||
componentDb.insertProjectAndSnapshot(project); | |||
componentDb.insertComponent(newFileDto(project, null)); | |||
insertNclocMetric(); | |||
@@ -514,8 +514,8 @@ public class ComponentTreeActionTest { | |||
public void fail_when_developer_is_unknown() { | |||
expectedException.expect(NotFoundException.class); | |||
ComponentDto developer = newDeveloper("developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto("project-uuid").setKey("project-key"); | |||
ComponentDto developer = newDeveloper(db.getDefaultOrganization(), "developer", "developer-uuid"); | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-uuid").setKey("project-key"); | |||
componentDb.insertDeveloperAndSnapshot(developer); | |||
SnapshotDto projectSnapshot = componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto file1 = componentDb.insertComponent(newFileDto(project, null, "file1-uuid")); | |||
@@ -535,7 +535,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_metric_keys_parameter_is_empty() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("The 'metricKeys' parameter must contain at least one metric key"); | |||
@@ -547,7 +547,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_a_metric_is_not_found() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
insertNclocMetric(); | |||
insertNewViolationsMetric(); | |||
expectedException.expect(NotFoundException.class); | |||
@@ -560,7 +560,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_search_query_have_less_than_3_characters() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
insertNclocMetric(); | |||
insertNewViolationsMetric(); | |||
expectedException.expect(BadRequestException.class); | |||
@@ -575,7 +575,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_insufficient_privileges() { | |||
userSession.anonymous().setGlobalPermissions(GlobalPermissions.QUALITY_PROFILE_ADMIN); | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
expectedException.expect(ForbiddenException.class); | |||
call(ws.newRequest() | |||
@@ -585,7 +585,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_sort_by_metric_and_no_metric_sort_provided() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException | |||
.expectMessage("To sort by a metric, the 's' parameter must contain 'metric' or 'metricPeriod', and a metric key must be provided in the 'metricSort' parameter"); | |||
@@ -599,7 +599,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_sort_by_metric_and_not_in_the_list_of_metric_keys() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("To sort by the 'complexity' metric, it must be in the list of metric keys in the 'metricKeys' parameter"); | |||
@@ -612,7 +612,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_sort_by_metric_period_and_no_metric_period_sort_provided() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("To sort by a metric period, the 's' parameter must contain 'metricPeriod' and the 'metricPeriodSort' must be provided."); | |||
@@ -626,7 +626,7 @@ public class ComponentTreeActionTest { | |||
@Test | |||
public void fail_when_paging_parameter_is_too_big() { | |||
componentDb.insertProjectAndSnapshot(newProjectDto("project-uuid")); | |||
componentDb.insertProjectAndSnapshot(newProjectDto(db.getDefaultOrganization(), "project-uuid")); | |||
insertNclocMetric(); | |||
expectedException.expect(BadRequestException.class); | |||
expectedException.expectMessage("The 'ps' parameter must be less than 500"); | |||
@@ -672,7 +672,7 @@ public class ComponentTreeActionTest { | |||
} | |||
private void insertJsonExampleData() { | |||
ComponentDto project = newProjectDto("project-id") | |||
ComponentDto project = newProjectDto(db.getDefaultOrganization(), "project-id") | |||
.setKey("MY_PROJECT") | |||
.setName("My Project") | |||
.setQualifier(Qualifiers.PROJECT); |
@@ -184,7 +184,7 @@ public class BulkDeleteActionTest { | |||
@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(); | |||
ws.newPostRequest("api/projects", ACTION).setParam(PARAM_IDS, "file-uuid").execute(); | |||
@@ -193,7 +193,7 @@ public class BulkDeleteActionTest { | |||
@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.getDefaultOrganization(), "project-uuid").setQualifier(Qualifiers.FILE)); | |||
dbSession.commit(); | |||
when(resourceType.getBooleanProperty(anyString())).thenReturn(false); | |||
@@ -203,7 +203,7 @@ public class BulkDeleteActionTest { | |||
private long insertNewProjectInDbAndReturnSnapshotId(int id) { | |||
String suffix = String.valueOf(id); | |||
ComponentDto project = ComponentTesting | |||
.newProjectDto("project-uuid-" + suffix) | |||
.newProjectDto(db.getDefaultOrganization(), "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 BulkDeleteActionTest { | |||
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(); |
@@ -62,25 +62,23 @@ public class IndexActionTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
DbClient dbClient = db.getDbClient(); | |||
PropertyDbTester propertyDb = new PropertyDbTester(db); | |||
ComponentDbTester componentDb = new ComponentDbTester(db); | |||
PropertyDefinitions definitions = new PropertyDefinitions(); | |||
private DbClient dbClient = db.getDbClient(); | |||
private PropertyDbTester propertyDb = new PropertyDbTester(db); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private PropertyDefinitions definitions = new PropertyDefinitions(); | |||
ComponentDto project; | |||
private ComponentDto project; | |||
WsActionTester ws = new WsActionTester(new IndexAction(dbClient, userSession, definitions)); | |||
private WsActionTester ws = new WsActionTester(new IndexAction(dbClient, userSession, definitions)); | |||
@Before | |||
public void setUp() throws Exception { | |||
project = componentDb.insertComponent(newProjectDto()); | |||
project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
} | |||
@Test |
@@ -55,12 +55,12 @@ public class SettingsFinderTest { | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
DbClient dbClient = db.getDbClient(); | |||
DbSession dbSession = db.getSession(); | |||
ComponentDbTester componentDb = new ComponentDbTester(db); | |||
PropertyDefinitions propertyDefinitions = new PropertyDefinitions(); | |||
private DbClient dbClient = db.getDbClient(); | |||
private DbSession dbSession = db.getSession(); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private PropertyDefinitions propertyDefinitions = new PropertyDefinitions(); | |||
SettingsFinder underTest = new SettingsFinder(dbClient, propertyDefinitions); | |||
private SettingsFinder underTest = new SettingsFinder(dbClient, propertyDefinitions); | |||
@Test | |||
public void return_global_settings() throws Exception { | |||
@@ -111,7 +111,7 @@ public class SettingsFinderTest { | |||
@Test | |||
public void return_component_settings() throws Exception { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
addDefinitions(PropertyDefinition.builder("property").defaultValue("default").build()); | |||
insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one")); | |||
@@ -126,7 +126,7 @@ public class SettingsFinderTest { | |||
@Test | |||
public void return_component_setting_even_if_no_definition() throws Exception { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
insertProperties(newComponentPropertyDto(project).setKey("property").setValue("one")); | |||
Multimap<String, Setting> settings = underTest.loadComponentSettings(dbSession, newHashSet("property"), project); | |||
@@ -136,7 +136,7 @@ public class SettingsFinderTest { | |||
@Test | |||
public void return_component_settings_with_property_set() throws Exception { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
addDefinitions(PropertyDefinition.builder("set1") | |||
.type(PROPERTY_SET) | |||
.fields(asList( | |||
@@ -162,10 +162,10 @@ public class SettingsFinderTest { | |||
@Test | |||
public void return_module_settings() throws Exception { | |||
ComponentDto project = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto project = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
ComponentDto module = componentDb.insertComponent(newModuleDto(project)); | |||
ComponentDto subModule = componentDb.insertComponent(newModuleDto(module)); | |||
ComponentDto anotherProject = componentDb.insertComponent(newProjectDto()); | |||
ComponentDto anotherProject = componentDb.insertComponent(newProjectDto(db.getDefaultOrganization())); | |||
insertProperties( | |||
newComponentPropertyDto(project).setKey("property").setValue("one"), |
@@ -41,6 +41,7 @@ import org.sonar.db.DbClient; | |||
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.PropertyDbTester; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
@@ -72,7 +73,7 @@ import static org.sonarqube.ws.Settings.Setting.ParentValueOneOfCase.PARENTVALUE | |||
public class ValuesActionTest { | |||
static Joiner COMMA_JOINER = Joiner.on(","); | |||
private static Joiner COMMA_JOINER = Joiner.on(","); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@@ -102,7 +103,8 @@ public class ValuesActionTest { | |||
when(pluginInfo.getKey()).thenReturn("plugin"); | |||
when(repository.getPluginInfos()).thenReturn(singletonList(pluginInfo)); | |||
scannerSettings.start(); | |||
project = componentDb.insertComponent(newProjectDto()); | |||
OrganizationDto organizationDto = db.organizations().insert(); | |||
project = componentDb.insertComponent(newProjectDto(organizationDto)); | |||
} | |||
@Test |
@@ -44,7 +44,7 @@ import org.sonar.server.ws.WsTester; | |||
public class ListActionTest { | |||
private static final String ORGANIZATION_UUID = "org1"; | |||
private static final String DEFAULT_ORGANIZATION_UUID = "org1"; | |||
@Rule | |||
public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings())); | |||
@@ -53,16 +53,16 @@ public class ListActionTest { | |||
@Rule | |||
public UserSessionRule userSessionRule = UserSessionRule.standalone(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
public DbTester db = DbTester.create(System2.INSTANCE) | |||
.setDefaultOrganizationUuid(DEFAULT_ORGANIZATION_UUID); | |||
private DbClient dbClient = db.getDbClient(); | |||
private TestIndex testIndex; | |||
private WsTester ws; | |||
@Before | |||
public void setUp() { | |||
testIndex = new TestIndex(es.client()); | |||
TestIndex testIndex = new TestIndex(es.client()); | |||
ws = new WsTester(new TestsWs(new ListAction(dbClient, testIndex, userSessionRule, new ComponentFinder(dbClient)))); | |||
} | |||
@@ -114,7 +114,7 @@ public class ListActionTest { | |||
TestFile1.dto(), | |||
TestFile2.dto(), | |||
new ComponentDto() | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setUuid(mainFileUuid) | |||
.setUuidPath(TestFile1.PROJECT_UUID + "." + mainFileUuid + ".") | |||
.setRootUuid(TestFile1.PROJECT_UUID) | |||
@@ -141,7 +141,7 @@ public class ListActionTest { | |||
TestFile1.dto(), | |||
TestFile2.dto(), | |||
new ComponentDto() | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setUuid(sourceFileUuid) | |||
.setUuidPath(TestFile1.PROJECT_UUID + "." + sourceFileUuid + ".") | |||
.setRootUuid(TestFile1.PROJECT_UUID) | |||
@@ -198,7 +198,7 @@ public class ListActionTest { | |||
userSessionRule.addProjectUuidPermissions(UserRole.USER, TestFile1.PROJECT_UUID); | |||
String mainFileUuid = "MAIN-FILE-UUID"; | |||
dbClient.componentDao().insert(db.getSession(), new ComponentDto() | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setUuid(mainFileUuid) | |||
.setUuidPath(TestFile1.PROJECT_UUID + "." + mainFileUuid + ".") | |||
.setRootUuid(TestFile1.PROJECT_UUID) | |||
@@ -237,7 +237,7 @@ public class ListActionTest { | |||
public static ComponentDto dto() { | |||
return new ComponentDto() | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setUuid(TestFile1.FILE_UUID) | |||
.setUuidPath(TestFile1.FILE_UUID_PATH) | |||
.setRootUuid(TestFile1.PROJECT_UUID) | |||
@@ -280,7 +280,7 @@ public class ListActionTest { | |||
public static ComponentDto dto() { | |||
return new ComponentDto() | |||
.setOrganizationUuid(ORGANIZATION_UUID) | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setUuid(FILE_UUID) | |||
.setUuidPath(FILE_UUID_PATH) | |||
.setRootUuid(TestFile2.PROJECT_UUID) |
@@ -75,8 +75,10 @@ import static org.sonar.test.JsonAssert.assertJson; | |||
public class ComponentActionTest { | |||
private static final String DEFAULT_ORGANIZATION_UUID = "defOrgUuid"; | |||
private static final String PROJECT_KEY = "polop"; | |||
private static final ComponentDto PROJECT = newProjectDto("abcd") | |||
.setOrganizationUuid(DEFAULT_ORGANIZATION_UUID) | |||
.setKey(PROJECT_KEY) | |||
.setName("Polop") | |||
.setDescription("test project") | |||
@@ -84,10 +86,9 @@ public class ComponentActionTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE) | |||
.setDefaultOrganizationUuid(DEFAULT_ORGANIZATION_UUID); | |||
@Rule | |||
public UserSessionRule userSessionRule = UserSessionRule.standalone(); | |||
@@ -49,6 +49,12 @@ public class ComponentDto implements Component { | |||
*/ | |||
private String organizationUuid; | |||
/** | |||
* The key of the organization the components belongs to. Read-only and nullable as it is populated only by some | |||
* requests joining on the organizations table. | |||
*/ | |||
private String organizationKey; | |||
/** | |||
* Non-empty and unique functional key | |||
*/ | |||
@@ -136,6 +142,10 @@ public class ComponentDto implements Component { | |||
return this; | |||
} | |||
public String getOrganizationKey() { | |||
return organizationKey; | |||
} | |||
public String uuid() { | |||
return uuid; | |||
} |
@@ -109,14 +109,16 @@ | |||
<select id="selectByUuids" parameterType="String" resultType="Component"> | |||
select | |||
<include refid="componentColumns"/> | |||
<include refid="componentColumns"/>, | |||
o.kee as organizationKey | |||
from projects p | |||
<where> | |||
and p.uuid in | |||
inner join organizations o on | |||
o.uuid = p.organization_uuid | |||
where | |||
p.uuid in | |||
<foreach collection="uuids" open="(" close=")" item="uuid" separator=","> | |||
#{uuid} | |||
</foreach> | |||
</where> | |||
</select> | |||
<select id="selectExistingUuids" parameterType="String" resultType="String"> |
@@ -32,6 +32,7 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.RowNotFoundException; | |||
import org.sonar.db.organization.OrganizationDto; | |||
import static com.google.common.collect.Lists.newArrayList; | |||
import static com.google.common.collect.Sets.newHashSet; | |||
@@ -74,6 +75,8 @@ public class ComponentDaoTest { | |||
ComponentDto result = underTest.selectByUuid(dbSession, "U1").get(); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.getOrganizationUuid()).isEqualTo("org1"); | |||
assertThat(result.getOrganizationKey()).isNull(); | |||
assertThat(result.uuid()).isEqualTo("U1"); | |||
assertThat(result.getUuidPath()).isEqualTo("uuid_path_of_U1"); | |||
assertThat(result.moduleUuid()).isEqualTo("module_uuid_of_U1"); | |||
@@ -250,7 +253,8 @@ public class ComponentDaoTest { | |||
assertThat(results).hasSize(1); | |||
ComponentDto result = results.get(0); | |||
assertThat(result).isNotNull(); | |||
assertThat(result.getOrganizationUuid()).isEqualTo("org1"); | |||
assertThat(result.getOrganizationKey()).isEqualTo("org1_key"); | |||
assertThat(result.uuid()).isEqualTo("U4"); | |||
assertThat(result.moduleUuid()).isEqualTo("module_uuid_of_U4"); | |||
assertThat(result.moduleUuidPath()).isEqualTo("module_uuid_path_of_U4"); | |||
@@ -859,8 +863,10 @@ public class ComponentDaoTest { | |||
@Test | |||
public void selectAncestors() { | |||
// organization | |||
OrganizationDto organization = db.organizations().insert(); | |||
// project -> module -> file | |||
ComponentDto project = newProjectDto(PROJECT_UUID); | |||
ComponentDto project = newProjectDto(organization, PROJECT_UUID); | |||
componentDb.insertProjectAndSnapshot(project); | |||
ComponentDto module = newModuleDto(MODULE_UUID, project); | |||
componentDb.insertComponent(module); |
@@ -36,6 +36,10 @@ public class OrganizationDbTester { | |||
return insert(OrganizationTesting.newOrganizationDto()); | |||
} | |||
public OrganizationDto insertForKey(String key) { | |||
return insert(OrganizationTesting.newOrganizationDto().setKey(key)); | |||
} | |||
/** | |||
* Insert the provided {@link OrganizationDto} and commit the session | |||
*/ |
@@ -1,5 +1,11 @@ | |||
<dataset> | |||
<organizations uuid="org1" | |||
kee="org1_key" | |||
name="org1_name" | |||
created_at="1000" | |||
updated_at="1000"/> | |||
<!-- Struts projects is authorized for all user --> | |||
<group_roles id="1" | |||
group_id="[null]" | |||
@@ -7,7 +13,6 @@ | |||
role="user" | |||
organization_uuid="org1"/> | |||
<!-- root project --> | |||
<projects organization_uuid="org1" | |||
id="1" | |||
@@ -54,7 +59,7 @@ | |||
created_at="1228222680000" | |||
build_date="1228222680000" | |||
version="[null]" | |||
/> | |||
/> | |||
<snapshots id="10" | |||
uuid="u10" | |||
component_uuid="ABCD" | |||
@@ -79,7 +84,7 @@ | |||
created_at="1228136280000" | |||
build_date="1228136280000" | |||
version="[null]" | |||
/> | |||
/> | |||
<!-- module --> | |||
<projects organization_uuid="org1" | |||
@@ -125,7 +130,7 @@ | |||
created_at="1228222680000" | |||
build_date="1228222680000" | |||
version="[null]" | |||
/> | |||
/> | |||
<!-- directory --> | |||
<projects organization_uuid="org1" | |||
@@ -172,7 +177,7 @@ | |||
created_at="1228222680000" | |||
build_date="1228222680000" | |||
version="[null]" | |||
/> | |||
/> | |||
<!-- file --> | |||
<projects organization_uuid="org1" | |||
@@ -220,7 +225,7 @@ | |||
created_at="1228222680000" | |||
build_date="1228222680000" | |||
version="[null]" | |||
/> | |||
/> | |||
<!-- Disabled projects --> | |||
<projects organization_uuid="org1" |