pj.scope = 'PRJ'
and pj.qualifier = 'TRK'
and pj.main_branch_project_uuid is null
- and upper(pj.name) like #{nameQuery, jdbcType=VARCHAR}
+ and (upper(pj.name) like #{nameOrKeyQuery, jdbcType=VARCHAR} or upper(pj.kee) like #{nameOrKeyQuery, jdbcType=VARCHAR})
order by pj.name ASC
</select>
<select id="selectDeselectedProjects" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ SELECT
+ pj.uuid as projectUuid,
+ pj.kee as projectKey,
+ pj.name as projectName,
+ pp.profile_key as profileKey
FROM components pj
- LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
- AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
+ LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
+ WHERE
+ pj.scope='PRJ'
+ AND pj.qualifier='TRK'
+ AND pj.main_branch_project_uuid is null
+ AND (upper(pj.name) like #{nameOrKeyQuery, jdbcType=VARCHAR} or upper(pj.kee) like #{nameOrKeyQuery, jdbcType=VARCHAR})
AND pp.profile_key IS NULL
ORDER BY pj.name ASC
</select>
<select id="selectProjectAssociations" resultType="org.sonar.db.qualityprofile.ProjectQprofileAssociationDto">
- SELECT pj.uuid as projectUuid, pj.kee as projectKey, pj.name as projectName, pp.profile_key as profileKey
+ SELECT
+ pj.uuid as projectUuid,
+ pj.kee as projectKey,
+ pj.name as projectName,
+ pp.profile_key as profileKey
FROM components pj
LEFT JOIN project_qprofiles pp ON pp.project_uuid = pj.uuid
AND pp.profile_key = #{profileUuid, jdbcType=VARCHAR}
- WHERE pj.scope='PRJ' AND pj.qualifier='TRK' AND pj.main_branch_project_uuid is null
- AND UPPER(pj.name) LIKE #{nameQuery, jdbcType=VARCHAR}
+ WHERE
+ pj.scope='PRJ'
+ AND pj.qualifier='TRK'
+ AND pj.main_branch_project_uuid is null
+ AND (upper(pj.name) like #{nameOrKeyQuery, jdbcType=VARCHAR} or upper(pj.kee) like #{nameOrKeyQuery, jdbcType=VARCHAR})
ORDER BY pj.name ASC
</select>
public void selectRuleProfile() {
RulesProfileDto rp = insertRulesProfile();
- assertThat(underTest.selectRuleProfile(dbSession, rp.getUuid()).getName()).isEqualTo(rp.getName());
+ assertThat(underTest.selectRuleProfile(dbSession, rp.getUuid())).extracting(RulesProfileDto::getName).isEqualTo(rp.getName());
assertThat(underTest.selectRuleProfile(dbSession, "missing")).isNull();
}
ProjectDto project2 = db.components().insertPrivateProjectDto();
ProjectDto project3 = db.components().insertPrivateProjectDto();
- db.getDbClient().projectDao().selectByUuid(dbSession, project1.getUuid()).get();
-
db.qualityProfiles().associateWithProject(project1, profile1);
db.qualityProfiles().associateWithProject(project2, profile1);
db.qualityProfiles().associateWithProject(project3, profile2);
@Test
public void selectByNameAndLanguage() {
- List<QProfileDto> sharedData = createSharedData();
+ createSharedData();
QProfileDto dto = underTest.selectByNameAndLanguage(dbSession, "Sonar Way", "java");
assertThat(dto).isNotNull();
QProfileDto jsProfile = db.qualityProfiles().insert(p -> p.setLanguage("js"));
db.qualityProfiles().associateWithProject(project1, javaProfile, jsProfile);
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "java").getKee())
- .isEqualTo(javaProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "js").getKee())
- .isEqualTo(jsProfile.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "cobol"))
- .isNull();
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project2, "java"))
- .isNull();
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "java")).extracting(QProfileDto::getKee).isEqualTo(javaProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "js")).extracting(QProfileDto::getKee).isEqualTo(jsProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project1, "cobol")).isNull();
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project2, "java")).isNull();
}
@Test
underTest.updateProjectProfileAssociation(dbSession, project, javaProfile2.getKee(), javaProfile1.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project, "java").getKee()).isEqualTo(javaProfile2.getKee());
- assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project, "js").getKee()).isEqualTo(jsProfile.getKee());
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project, "java")).extracting(QProfileDto::getKee).isEqualTo(javaProfile2.getKee());
+ assertThat(underTest.selectAssociatedToProjectAndLanguage(dbSession, project, "js")).extracting(QProfileDto::getKee).isEqualTo(jsProfile.getKee());
}
@Test
ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"));
ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"));
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"));
- ComponentDto project4 = db.components().insertPrivateProject(t -> t.setName("Project4 name"));
- ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
+ db.components().insertPrivateProject(t -> t.setName("Project4 name"));
+ db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
ComponentDto project1 = db.components().insertPrivateProject(t -> t.setName("Project1 name"));
ComponentDto project2 = db.components().insertPrivateProject(t -> t.setName("Project2 name"));
ComponentDto project3 = db.components().insertPrivateProject(t -> t.setName("Project3 name"));
- ComponentDto branch = db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
+ db.components().insertProjectBranch(project1, t -> t.setKey("branch"));
QProfileDto profile1 = newQualityProfileDto();
db.qualityProfiles().insert(profile1);
@Test
public void selectUuidsOfCustomRulesProfiles_returns_the_custom_profiles_with_specified_name() {
QProfileDto outdatedProfile1 = db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setLanguage("java").setName("foo"));
- QProfileDto differentLanguage = db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
- QProfileDto differentName = db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));
+ db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setLanguage("cobol").setName("foo"));
+ db.qualityProfiles().insert(p -> p.setIsBuiltIn(false).setLanguage("java").setName("bar"));
Collection<String> keys = underTest.selectUuidsOfCustomRulesProfiles(dbSession, "java", "foo");
assertThat(keys).containsOnly(outdatedProfile1.getRulesProfileUuid());
assertThat(result).isEmpty();
}
+ @Test
+ public void selectProjectAssociations_shouldFindResult_whenQueryMatchingKey() {
+ ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key"));
+ QProfileDto qProfileDto = db.qualityProfiles().insert();
+
+ List<ProjectQprofileAssociationDto> results = underTest.selectProjectAssociations(dbSession, qProfileDto, "key");
+
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ }
+
+ @Test
+ public void selectSelectedProjects_shouldFindResult_whenQueryMatchingKey() {
+ ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key"));
+ QProfileDto qProfileDto = db.qualityProfiles().insert();
+ db.qualityProfiles().associateWithProject(db.components().getProjectDto(privateProject), qProfileDto);
+
+ List<ProjectQprofileAssociationDto> results = underTest.selectSelectedProjects(dbSession, qProfileDto, "key");
+
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ }
+
+ @Test
+ public void selectDeselectedProjects_shouldFindResult_whenQueryMatchingKey() {
+ ComponentDto privateProject = db.components().insertPrivateProject(project -> project.setName("project name"), project -> project.setKey("project_key"));
+ QProfileDto qProfileDto = db.qualityProfiles().insert();
+
+ List<ProjectQprofileAssociationDto> results = underTest.selectDeselectedProjects(dbSession, qProfileDto, "key");
+
+ assertThat(results).extracting(ProjectQprofileAssociationDto::getProjectUuid).containsOnly(privateProject.uuid());
+ }
+
private List<QProfileDto> createSharedData() {
QProfileDto dto1 = new QProfileDto()
.setKee("java_sonar_way")
import org.sonar.db.user.UserDto;
import org.sonar.server.exceptions.NotFoundException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.TestRequest;
import org.sonar.server.ws.WsActionTester;
import static org.assertj.core.api.Assertions.assertThat;
}
@Test
- public void filter_on_name() {
+ public void filter_on_name_and_key() {
ProjectDto project1 = db.components().insertPublicProjectDto(p -> p.setName("Project One"));
ProjectDto project2 = db.components().insertPublicProjectDto(p -> p.setName("Project Two"));
ProjectDto project3 = db.components().insertPublicProjectDto(p -> p.setName("Project Three"));
- ProjectDto project4 = db.components().insertPublicProjectDto(p -> p.setName("Project Four"));
+ db.components().insertPublicProjectDto(p -> p.setName("Project Four"));
+ ProjectDto project5 = db.components().insertPublicProjectDto(p -> p.setDbKey("Project the fifth"));
+
QProfileDto qualityProfile = db.qualityProfiles().insert();
associateProjectsWithProfile(qualityProfile, project1, project2);
" \"key\": \"" + project2.getKey() + "\",\n" +
" \"name\": \"" + project2.getName() + "\",\n" +
" \"selected\": true\n" +
+ " },\n" +
+ " {\n" +
+ " \"key\": \"" + project5.getKey() + "\",\n" +
+ " \"name\": \"" + project5.getName() + "\",\n" +
+ " \"selected\": false\n" +
" }\n" +
" ]}\n");
}
@Test
public void fail_on_nonexistent_profile() {
- assertThatThrownBy(() -> {
- ws.newRequest()
- .setParam(PARAM_KEY, "unknown")
- .execute();
- })
- .isInstanceOf(NotFoundException.class);
+ TestRequest testRequest = ws.newRequest().setParam(PARAM_KEY, "unknown");
+ assertThatThrownBy(testRequest::execute).isInstanceOf(NotFoundException.class);
}
@Test
assertThat(definition.responseExampleAsString()).isNotEmpty();
assertThat(definition.params()).extracting(Param::key).containsExactlyInAnyOrder("key", "p", "ps", "q", "selected");
Param profile = definition.param("key");
+ assertThat(profile).isNotNull();
assertThat(profile.deprecatedKey()).isNullOrEmpty();
assertThat(definition.param("p")).isNotNull();
assertThat(definition.param("ps")).isNotNull();
- Param query = definition.param("q");
+ assertThat(definition.param("q")).isNotNull();
}
private void associateProjectsWithProfile(QProfileDto profile, ProjectDto... projects) {