aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-db/src/test/java/org
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-01-27 15:55:17 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-01-30 14:16:58 +0100
commit7a1e3ddaf9765e51e48bd1fc454ffb33b0cbde06 (patch)
tree58422a7381bb37153e4ab3197ab11ceaa999169c /sonar-db/src/test/java/org
parent2072b8cf07b2c18c53a7a436df50920294a1f50a (diff)
downloadsonarqube-7a1e3ddaf9765e51e48bd1fc454ffb33b0cbde06.tar.gz
sonarqube-7a1e3ddaf9765e51e48bd1fc454ffb33b0cbde06.zip
SONAR-8649 add organization parameter to api/projects/provisioned
Diffstat (limited to 'sonar-db/src/test/java/org')
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java73
-rw-r--r--sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java4
2 files changed, 53 insertions, 24 deletions
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 45310b38792..632d98a3d8f 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -523,49 +523,74 @@ public class ComponentDaoTest {
@Test
public void select_projects() {
- db.prepareDbUnit(getClass(), "select_provisioned_projects.xml");
-
- List<ComponentDto> result = underTest.selectProjects(dbSession);
-
- assertThat(result).extracting("id").containsOnly(42L, 1L);
+ OrganizationDto organization = db.organizations().insert();
+ ComponentDto provisionedProject = db.components().insertProject();
+ ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {});
+ String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
+ String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
+ String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
+
+ assertThat(underTest.selectProjects(dbSession))
+ .extracting(ComponentDto::uuid)
+ .containsOnly(provisionedProject.uuid(), projectUuid);
}
@Test
public void select_provisioned() {
- db.prepareDbUnit(getClass(), "select_provisioned_projects.xml");
+ OrganizationDto organization = db.organizations().insert();
+ ComponentDto provisionedProject = db.components().insertComponent(newProjectDto(organization).setKey("provisioned.project").setName("Provisioned Project"));
+ ComponentDto provisionedView = db.components().insertView(organization, (dto) -> {});
+ String projectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization)).getComponentUuid();
+ String disabledProjectUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization).setEnabled(false)).getComponentUuid();
+ String viewUuid = db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization)).getComponentUuid();
Set<String> projectQualifiers = newHashSet(Qualifiers.PROJECT);
- assertProvisionedKeys(null, projectQualifiers, 0, 10).containsExactly("org.provisioned.project");
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsOnly(provisionedProject.uuid());
// pagination
- assertProvisionedKeys(null, projectQualifiers, 2, 10).isEmpty();
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, projectQualifiers, new RowBounds(2, 10)))
+ .isEmpty();
// filter on qualifiers
- assertProvisionedKeys(null, newHashSet("XXX"), 0, 10).isEmpty();
- assertProvisionedKeys(null, newHashSet(Qualifiers.PROJECT, "XXX"), 0, 10).containsExactly("org.provisioned.project");
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet("XXX"), new RowBounds(0, 10)))
+ .isEmpty();
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, "XXX"), new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsOnly(provisionedProject.uuid());
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT, Qualifiers.VIEW), new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsOnly(provisionedProject.uuid(), provisionedView.uuid());
// match key
- assertProvisionedKeys("org.provisioned.project", projectQualifiers, 0, 10).containsExactly("org.provisioned.project");
- assertProvisionedKeys("ORG.provisioned.PROJECT", projectQualifiers, 0, 10).containsExactly("org.provisioned.project");
- assertProvisionedKeys("missing", projectQualifiers, 0, 10).isEmpty();
- assertProvisionedKeys("to be escaped '\"\\%", projectQualifiers, 0, 10).isEmpty();
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), provisionedProject.getKey(), projectQualifiers, new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsExactly(provisionedProject.uuid());
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "pROvisiONed.proJEcT", projectQualifiers, new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsExactly(provisionedProject.uuid());
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "missing", projectQualifiers, new RowBounds(0, 10)))
+ .isEmpty();
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "to be escaped '\"\\%", projectQualifiers, new RowBounds(0, 10)))
+ .isEmpty();
// match name
- assertProvisionedKeys("ned proj", projectQualifiers, 0, 10).containsExactly("org.provisioned.project");
- }
-
- private ListAssert<String> assertProvisionedKeys(@Nullable String textQuery, Set<String> qualifiers, int offset, int limit) {
- List<ComponentDto> result = underTest.selectProvisioned(dbSession, textQuery, qualifiers, new RowBounds(offset, limit));
- return assertThat(result).extracting(ComponentDto::getKey);
+ assertThat(underTest.selectProvisioned(dbSession, organization.getUuid(), "ned proj", projectQualifiers, new RowBounds(0, 10)))
+ .extracting(ComponentDto::uuid)
+ .containsExactly(provisionedProject.uuid());
}
@Test
public void count_provisioned() {
- db.prepareDbUnit(getClass(), "select_provisioned_projects.xml");
+ OrganizationDto organization = db.organizations().insert();
+ db.components().insertProject(organization);
+ db.components().insertProjectAndSnapshot(ComponentTesting.newProjectDto(organization));
+ db.components().insertProjectAndSnapshot(ComponentTesting.newView(organization));
- assertThat(underTest.countProvisioned(dbSession, null, newHashSet(Qualifiers.PROJECT))).isEqualTo(1);
- assertThat(underTest.countProvisioned(dbSession, null, newHashSet(Qualifiers.VIEW))).isEqualTo(0);
- assertThat(underTest.countProvisioned(dbSession, null, newHashSet(Qualifiers.VIEW, Qualifiers.PROJECT))).isEqualTo(1);
+ assertThat(underTest.countProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.PROJECT))).isEqualTo(1);
+ assertThat(underTest.countProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.VIEW))).isEqualTo(0);
+ assertThat(underTest.countProvisioned(dbSession, organization.getUuid(), null, newHashSet(Qualifiers.VIEW, Qualifiers.PROJECT))).isEqualTo(1);
}
@Test
diff --git a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
index 4173b890f2c..67d438cb847 100644
--- a/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
+++ b/sonar-db/src/test/java/org/sonar/db/component/ComponentDbTester.java
@@ -94,6 +94,10 @@ public class ComponentDbTester {
return insertComponentImpl(newView(db.getDefaultOrganization()), dtoPopulator);
}
+ public ComponentDto insertView(OrganizationDto organizationDto) {
+ return insertComponentImpl(newView(organizationDto), dto -> {});
+ }
+
public ComponentDto insertView(OrganizationDto organizationDto, Consumer<ComponentDto> dtoPopulator) {
return insertComponentImpl(newView(organizationDto), dtoPopulator);
}