aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java b/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java
new file mode 100644
index 00000000000..f3dfdd8164a
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/component/ComponentQueryTest.java
@@ -0,0 +1,81 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.component;
+
+import org.junit.Test;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+
+public class ComponentQueryTest {
+
+ @Test
+ public void should_build_query() throws Exception {
+ ComponentQuery query = ComponentQuery.builder()
+ .keys(newArrayList("org.codehaus"))
+ .names(newArrayList("Sona"))
+ .qualifiers(newArrayList("TRK"))
+ .pageSize(10)
+ .pageIndex(2)
+ .sort(ComponentQuery.SORT_BY_NAME)
+ .asc(true)
+ .build();
+ assertThat(query.keys()).containsOnly("org.codehaus");
+ assertThat(query.names()).containsOnly("Sona");
+ assertThat(query.qualifiers()).containsOnly("TRK");
+ assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME);
+ assertThat(query.asc()).isTrue();
+ assertThat(query.pageSize()).isEqualTo(10);
+ assertThat(query.pageIndex()).isEqualTo(2);
+ }
+
+ @Test
+ public void should_accept_null_sort() throws Exception {
+ ComponentQuery query = ComponentQuery.builder().sort(null).build();
+ assertThat(query.sort()).isNull();
+ }
+
+ @Test
+ public void should_sort_by_name_asc_by_default() throws Exception {
+ ComponentQuery query = ComponentQuery.builder().build();
+ assertThat(query.sort()).isEqualTo(ComponentQuery.SORT_BY_NAME);
+ assertThat(query.asc()).isTrue();
+ }
+
+ @Test
+ public void should_throw_exception_if_sort_is_not_valid() throws Exception {
+ try {
+ ComponentQuery.builder()
+ .sort("UNKNOWN")
+ .build();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalArgumentException.class).hasMessage("Bad sort field: UNKNOWN");
+ }
+ }
+
+ @Test
+ public void test_default_page_index_and_size() throws Exception {
+ ComponentQuery query = ComponentQuery.builder().build();
+ assertThat(query.pageSize()).isEqualTo(ComponentQuery.DEFAULT_PAGE_SIZE);
+ assertThat(query.pageIndex()).isEqualTo(ComponentQuery.DEFAULT_PAGE_INDEX);
+ }
+
+}