]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5594 The name of a quality profile cannot be blank
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 6 Oct 2014 09:35:26 +0000 (11:35 +0200)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Mon, 6 Oct 2014 09:35:26 +0000 (11:35 +0200)
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileFactory.java
server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileFactoryMediumTest.java

index 65c0f46025f83c6f347005625cd67fa7786db298..f789f957028e6f975251eba6d53cbb86d460237b 100644 (file)
@@ -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)));
index b01071454dc9f9ba50b3975714ca8832e99bbc55..21340c976c12e3bbf39686afcdfce6cb34b23dd8 100644 (file)
@@ -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");