From: Jean-Baptiste Lievremont Date: Mon, 6 Oct 2014 09:35:26 +0000 (+0200) Subject: SONAR-5594 The name of a quality profile cannot be blank X-Git-Tag: 4.5.1-RC1~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9d4bf23a1ef8dec3baa30466bd76cf387204e95;p=sonarqube.git SONAR-5594 The name of a quality profile cannot be blank --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java index 65c0f46025f..f789f957028 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java @@ -72,6 +72,9 @@ public class QProfileFactory implements ServerComponent { } private QualityProfileDto doCreate(DbSession dbSession, QProfileName name) { + if (StringUtils.isEmpty(name.getName())) { + throw new BadRequestException("quality_profiles.profile_name_cant_be_blank"); + } Date now = new Date(); for (int i = 0; i < 20; i++) { String key = Slug.slugify(String.format("%s %s %s", name.getLanguage(), name.getName(), RandomStringUtils.randomNumeric(5))); diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java index b01071454dc..21340c976c1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java @@ -41,7 +41,9 @@ import org.sonar.server.user.MockUserSession; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; -import static org.sonar.server.qualityprofile.QProfileTesting.*; +import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P1_KEY; +import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P2_KEY; +import static org.sonar.server.qualityprofile.QProfileTesting.XOO_P3_KEY; public class QProfileFactoryMediumTest { @@ -88,6 +90,26 @@ public class QProfileFactoryMediumTest { assertThat(db.qualityProfileDao().findAll(dbSession)).hasSize(1); } + @Test + public void fail_to_create_if_name_empty() { + QProfileName name = new QProfileName("xoo", null); + try { + factory.create(dbSession, name); + fail(); + } catch (BadRequestException e) { + assertThat(e).hasMessage("quality_profiles.profile_name_cant_be_blank"); + } + + name = new QProfileName("xoo", ""); + try { + factory.create(dbSession, name); + fail(); + } catch (BadRequestException e) { + assertThat(e).hasMessage("quality_profiles.profile_name_cant_be_blank"); + } + } + + @Test public void fail_to_create_if_already_exists() { QProfileName name = new QProfileName("xoo", "P1");