]> source.dussan.org Git - sonarqube.git/commitdiff
Add unit tests to widgets
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 13:55:16 +0000 (14:55 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 4 Dec 2012 13:55:16 +0000 (14:55 +0100)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/MeasureFilterListWidget.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TreemapWidget.java
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/welcome.html.erb
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/MyFavouritesFilterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/filters/ProjectFilterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/CoverageWidgetTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/ItCoverageWidgetTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java [new file with mode: 0644]
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java [new file with mode: 0644]

index 15ac89497cca0686df30db4d789831a5daec37d2..2c4615362e746f315f27fcc85a782530ed5ce81f 100644 (file)
@@ -33,7 +33,7 @@ import static org.sonar.api.web.WidgetScope.GLOBAL;
 @WidgetScope(GLOBAL)
 @WidgetProperties({
   @WidgetProperty(key = MeasureFilterListWidget.FILTER_PROPERTY, type = WidgetPropertyType.FILTER, optional = false),
-  @WidgetProperty(key = MeasureFilterListWidget.PAGE_SIZE_PROPERTY, type = WidgetPropertyType.INTEGER, optional = true)
+  @WidgetProperty(key = MeasureFilterListWidget.PAGE_SIZE_PROPERTY, type = WidgetPropertyType.INTEGER, defaultValue = "30")
 }
 )
 public class MeasureFilterListWidget extends AbstractRubyTemplate implements RubyRailsWidget {
index 5ac71e2f6611884ff879afbb6cec1be085b0520d..79d44b52137d791e8e8a6ccc8787160ded437051 100644 (file)
@@ -34,7 +34,7 @@ public class TreemapWidget extends AbstractRubyTemplate implements RubyRailsWidg
   }
 
   public String getTitle() {
-    return "Treemap of components";
+    return "Treemap of Components";
   }
 
   @Override
index e97c37e8b77b8b2c3ecea5064eb40273f4997c9c..a3e651d4f03d0deb9a1b759de3689cb9e66e29a5 100644 (file)
@@ -1,9 +1 @@
-<h3>Welcome to Sonar Dashboard</h3>
-<p>Since you are able to read this, it means that you have successfully started your Sonar server. Well done!</p>
-<p>If you have not removed this text, it also means that you have not yet played much with Sonar. So here are a few pointers for your next step:</p>
-<ul class="bullet">
-  <li>Do you now want to <a href="http://docs.codehaus.org/x/P4LEBg">run analysis</a> on a project?</li>
-  <li>Maybe start <a href="http://docs.codehaus.org/x/EYDECQ">customizing dashboards</a>?</li>
-  <li>Or simply browse the <a href="http://docs.codehaus.org/x/EoDEBg">complete documentation</a>?</li>
-  <li>If you have a question or an issue, please report it on the <a href="http://www.sonarsource.org/support/support/">mailing list</a>.</li>
-</ul>
\ No newline at end of file
+<%= message('widget.welcome.html') -%>
\ No newline at end of file
index 78ceaf77c702fb08c8c2b09fd39e9a3c8b66b873..e9faed66f2174429ca671242f94d7dbdc41d9932 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.filters;
 
 import org.junit.Test;
 import org.sonar.api.web.Filter;
+import org.sonar.plugins.core.CorePlugin;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -37,4 +38,9 @@ public class MyFavouritesFilterTest {
     assertThat(filter.getCriteria()).isEmpty();
     assertThat(filter.getColumns()).hasSize(3);
   }
+
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(MyFavouritesFilter.class);
+  }
 }
index e918d19f36af216117ea781f2592e95f1e939fcf..32d46c9455f1d676458e67b8faddcc174a14e422 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.plugins.core.filters;
 
 import org.junit.Test;
 import org.sonar.api.web.Filter;
+import org.sonar.plugins.core.CorePlugin;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -28,7 +29,7 @@ public class ProjectFilterTest {
   @Test
   public void should_create_filter() {
     ProjectFilter template = new ProjectFilter();
-    
+
     Filter filter = template.createFilter();
 
     assertThat(template.getName()).isEqualTo("Projects");
@@ -36,4 +37,9 @@ public class ProjectFilterTest {
     assertThat(filter.getCriteria()).hasSize(1);
     assertThat(filter.getColumns()).hasSize(7);
   }
+
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(ProjectFilter.class);
+  }
 }
index 8caa30430c094768b47838344d22d593e5c6c99a..5c666d2d58b7a72dccc8ee918bdb1f44b5762e63 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.plugins.core.widgets;
 
 import org.junit.Test;
+import org.sonar.plugins.core.CorePlugin;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -33,9 +34,13 @@ public class CoverageWidgetTest {
   }
 
   @Test
-  public void should_use_relative_path_for_template() {
+  public void should_find_template() {
     CoverageWidget widget = new CoverageWidget();
+    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
+  }
 
-    assertThat(widget.getTemplatePath()).startsWith("/");
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(CoverageWidget.class);
   }
 }
index 7bf32fea1d2863da579876024dd4f82152ee034e..ffde53f41a80b1cc2d12425ba240b6141f310fe5 100644 (file)
@@ -19,7 +19,9 @@
  */
 package org.sonar.plugins.core.widgets;
 
+import com.google.common.io.Resources;
 import org.junit.Test;
+import org.sonar.plugins.core.CorePlugin;
 
 import static org.fest.assertions.Assertions.assertThat;
 
@@ -33,9 +35,13 @@ public class ItCoverageWidgetTest {
   }
 
   @Test
-  public void should_use_relative_path_for_template() {
+  public void should_find_template() {
     ItCoverageWidget widget = new ItCoverageWidget();
+    assertThat(ItCoverageWidget.class.getResource(widget.getTemplatePath())).isNotNull();
+  }
 
-    assertThat(widget.getTemplatePath()).startsWith("/");
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(ItCoverageWidget.class);
   }
 }
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/TreemapWidgetTest.java
new file mode 100644 (file)
index 0000000..5337fae
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+import org.junit.Test;
+import org.sonar.plugins.core.CorePlugin;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class TreemapWidgetTest {
+  @Test
+  public void should_define_widget() {
+    TreemapWidget widget = new TreemapWidget();
+
+    assertThat(widget.getId()).isEqualTo("treemap-widget");
+    assertThat(widget.getTitle()).isEqualTo("Treemap of Components");
+  }
+
+  @Test
+  public void should_find_template() {
+    TreemapWidget widget = new TreemapWidget();
+    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
+  }
+
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(TreemapWidget.class);
+  }
+}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/widgets/WelcomeWidgetTest.java
new file mode 100644 (file)
index 0000000..dbe5d45
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
+ */
+package org.sonar.plugins.core.widgets;
+
+import org.junit.Test;
+import org.sonar.plugins.core.CorePlugin;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class WelcomeWidgetTest {
+  @Test
+  public void should_define_widget() {
+    WelcomeWidget widget = new WelcomeWidget();
+
+    assertThat(widget.getId()).isEqualTo("welcome");
+    assertThat(widget.getTitle()).isEqualTo("Welcome");
+  }
+
+  @Test
+  public void should_find_template() {
+    WelcomeWidget widget = new WelcomeWidget();
+    assertThat(WelcomeWidget.class.getResource(widget.getTemplatePath())).isNotNull();
+  }
+
+  @Test
+  public void should_be_registered_as_an_extension() {
+    assertThat(new CorePlugin().getExtensions()).contains(WelcomeWidget.class);
+  }
+}