import org.assertj.core.groups.Tuple;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import org.sonar.api.impl.utils.AlwaysIncreasingSystem2;
import org.sonar.api.utils.System2;
import org.sonar.db.DbTester;
assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false, true);
}
+ @Test
+ void update_aiCodeFixEnabledPerProject() {
+ ProjectDto dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true);
+ ProjectDto dto2 = createProject("o1", "p2");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(0), "uuid_o1_p1", true);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(1), "uuid_o1_p2", false);
+
+ projectDao.update(db.getSession(), projectsByUuids.get(0).setAiCodeFixEnabled(false));
+ projectDao.update(db.getSession(), projectsByUuids.get(1).setAiCodeFixEnabled(true));
+
+ projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(0), "uuid_o1_p1", false);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(1), "uuid_o1_p2", true);
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = { true, false })
+ void update_aiCodeFixEnabledForAllProjects(boolean aiCodeFixEnablement) {
+ ProjectDto dto1 = createProject("o1", "p1").setAiCodeFixEnabled(true);
+ ProjectDto dto2 = createProject("o1", "p2");
+
+ projectDao.insert(db.getSession(), dto1);
+ projectDao.insert(db.getSession(), dto2);
+
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(0), "uuid_o1_p1", true);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(1), "uuid_o1_p2", false);
+
+ projectDao.updateAiCodeFixEnablementForAllProjects(db.getSession(), aiCodeFixEnablement);
+
+ projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
+ assertThat(projectsByUuids).hasSize(2);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(0), "uuid_o1_p1", aiCodeFixEnablement);
+ assertProjectAiCodeFixEnablement(projectsByUuids.get(1), "uuid_o1_p2", aiCodeFixEnablement);
+ }
+
@Test
void select_by_uuids() {
ProjectDto dto1 = createProject("o1", "p1");
.containsExactly(name, kee, kee, uuid, desc, tags, isPrivate, isAiCodeAssurance);
}
+ private void assertProjectAiCodeFixEnablement(ProjectDto dto, String uuid, boolean isAiCodeFixEnabled) {
+ assertThat(dto).extracting("uuid", "aiCodeFixEnabled").containsExactly(uuid, isAiCodeFixEnabled);
+ }
+
private ProjectDto createProject(String org, String name) {
return new ProjectDto()
.setName("projectName_" + name)
update projects set
name = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
+ ai_code_fix_enabled = #{aiCodeFixEnabled, jdbcType=BOOLEAN},
updated_at = #{updatedAt,jdbcType=BIGINT}
where
uuid = #{uuid,jdbcType=VARCHAR}
uuid = #{uuid,jdbcType=VARCHAR}
</update>
+ <update id="updateAiCodeFixEnablementForAllProjects">
+ update projects set
+ ai_code_fix_enabled = #{aiCodeFixEnabled,jdbcType=BOOLEAN},
+ updated_at = #{updatedAt,jdbcType=BIGINT}
+ </update>
+
<update id="updateNcloc">
update projects set
ncloc = #{ncloc,jdbcType=BIGINT}