]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 19 Dec 2014 10:18:31 +0000 (11:18 +0100)
committerJean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com>
Fri, 19 Dec 2014 10:18:35 +0000 (11:18 +0100)
server/sonar-server/src/main/java/org/sonar/server/component/ComponentService.java
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueDoc.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/SearchAction.java
server/sonar-server/src/test/java/org/sonar/server/es/request/ProxyIndexRequestBuilderTest.java
sonar-core/src/test/java/org/sonar/core/issue/db/IssueDtoTest.java

index c70a4c906097815e716fe2e31eb902c30bb0f529..45a98f8c4f34b4ba4392b8588e697fff59db3081 100644 (file)
 
 package org.sonar.server.component;
 
-import com.google.common.base.Joiner;
-
-import org.apache.commons.collections.CollectionUtils;
-import com.google.common.base.Function;
 import com.google.common.base.Function;
+import com.google.common.base.Joiner;
 import com.google.common.collect.Collections2;
-import org.sonar.server.exceptions.NotFoundException;
+import org.apache.commons.collections.CollectionUtils;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.web.UserRole;
 import org.sonar.core.component.ComponentDto;
@@ -34,6 +31,7 @@ import org.sonar.core.persistence.DbSession;
 import org.sonar.core.preview.PreviewCache;
 import org.sonar.core.resource.ResourceKeyUpdaterDao;
 import org.sonar.server.db.DbClient;
+import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.user.UserSession;
 
 import javax.annotation.CheckForNull;
index 005e8e467e256b1025f2c78b70329c3861ee01c3..c156bf24d2c36ebc8f2633c61d5df999449bec35 100644 (file)
@@ -296,6 +296,7 @@ public class IssueDoc extends BaseDoc implements Issue {
     setField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, s);
   }
 
+  @Override
   @CheckForNull
   public Collection<String> tags() {
     return getNullableField(IssueIndexDefinition.FIELD_ISSUE_TAGS);
index a63cacee26714a83a7415f0098234ba907620932..6c2963241fb84f24110cbae1b94ae6f747a87075 100644 (file)
@@ -78,6 +78,7 @@ import static com.google.common.collect.Sets.newHashSet;
 
 public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
 
+
   public static final String SEARCH_ACTION = "search";
 
   private static final String ACTIONS_EXTRA_FIELD = "actions";
@@ -88,6 +89,8 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
 
   private static final String EXTRA_FIELDS_PARAM = "extra_fields";
 
+  private static final String INTERNAL_PARAMETER_DISCLAIMER = "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter.";
+
   private final IssueChangeDao issueChangeDao;
   private final IssueService service;
   private final IssueActionsWriter actionsWriter;
@@ -210,7 +213,7 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       .setDescription("Deprecated since 5.1. See componentKeys.");
     action.createParam(IssueFilterParameters.COMPONENT_UUIDS)
       .setDescription("To retrieve issues associated to a specific list of components (comma-separated list of component UUIDs). " +
-        "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter." +
+        INTERNAL_PARAMETER_DISCLAIMER +
         "A component can be a project, module, directory or file." +
         "If this parameter is set, componentKeys must not be set.")
       .setExampleValue("584a89f2-8037-4f7b-b82c-8b45d2d63fb2");
@@ -219,13 +222,13 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       .setDescription("Deprecated since 5.1. See projectKeys");
     action.createParam(IssueFilterParameters.PROJECT_KEYS)
       .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project keys). " +
-        "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter." +
+        INTERNAL_PARAMETER_DISCLAIMER +
         "If this parameter is set, projectUuids must not be set.")
       .setDeprecatedKey(IssueFilterParameters.PROJECTS)
       .setExampleValue("org.apache.struts:struts:org.apache.struts.Action");
     action.createParam(IssueFilterParameters.PROJECT_UUIDS)
       .setDescription("To retrieve issues associated to a specific list of projects (comma-separated list of project UUIDs). " +
-        "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter." +
+        INTERNAL_PARAMETER_DISCLAIMER +
         "Views are not supported. If this parameter is set, projectKeys must not be set.")
       .setExampleValue("7d8749e8-3070-4903-9188-bdd82933bb92");
 
@@ -235,13 +238,13 @@ public class SearchAction extends SearchRequestHandler<IssueQuery, Issue> {
       .setDescription("Deprecated since 5.1. See moduleUuids.");
     action.createParam(IssueFilterParameters.MODULE_KEYS)
       .setDescription("To retrieve issues associated to a specific list of modules (comma-separated list of module keys). " +
-        "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter." +
+        INTERNAL_PARAMETER_DISCLAIMER +
         "Views are not supported. If this parameter is set, componentRootUuids must not be set.")
       .setDeprecatedKey(IssueFilterParameters.COMPONENT_ROOTS)
       .setExampleValue("org.apache.struts:struts");
     action.createParam(IssueFilterParameters.MODULE_UUIDS)
       .setDescription("To retrieve issues associated to a specific list of components and their sub-components (comma-separated list of component UUIDs). " +
-        "This parameter is mostly used by the Issues page, please prefer usage of the componentKeys parameter." +
+        INTERNAL_PARAMETER_DISCLAIMER +
         "Views are not supported. If this parameter is set, moduleKeys must not be set.")
       .setDeprecatedKey(IssueFilterParameters.COMPONENT_ROOT_UUIDS)
       .setExampleValue("7d8749e8-3070-4903-9188-bdd82933bb92");
index be8854a87a0807c06634fff7f5ee23abbc2a30b3..4a78049279e120eabde69ea91d0b2741bb5f79cc 100644 (file)
@@ -39,6 +39,7 @@ public class ProxyIndexRequestBuilderTest {
 
   @Test
   public void index_with_index_type_and_id() {
+    esTester.setProfilingLevel(Profiling.Level.FULL);
     IndexResponse response = esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE)
       .setSource(FakeIndexDefinition.newDoc(42))
       .get();
@@ -57,6 +58,20 @@ public class ProxyIndexRequestBuilderTest {
 
   @Test
   public void fail_if_bad_query() throws Exception {
+    esTester.setProfilingLevel(Profiling.Level.FULL);
+    IndexRequestBuilder requestBuilder = esTester.client().prepareIndex("unknownIndex", "unknownType");
+    try {
+      requestBuilder.get();
+      fail();
+    } catch (Exception e) {
+      assertThat(e).isInstanceOf(IllegalStateException.class);
+      assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'null' on index 'unknownIndex' on type 'unknownType'");
+    }
+  }
+
+  @Test
+  public void fail_if_bad_query_with_basic_profiling() throws Exception {
+    esTester.setProfilingLevel(Profiling.Level.BASIC);
     IndexRequestBuilder requestBuilder = esTester.client().prepareIndex("unknownIndex", "unknownType");
     try {
       requestBuilder.get();
@@ -69,6 +84,7 @@ public class ProxyIndexRequestBuilderTest {
 
   @Test
   public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+    esTester.setProfilingLevel(Profiling.Level.FULL);
     try {
       esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).get("1");
       fail();
@@ -79,6 +95,7 @@ public class ProxyIndexRequestBuilderTest {
 
   @Test
   public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
+    esTester.setProfilingLevel(Profiling.Level.FULL);
     try {
       esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).get(TimeValue.timeValueMinutes(1));
       fail();
@@ -89,6 +106,7 @@ public class ProxyIndexRequestBuilderTest {
 
   @Test
   public void do_not_support_execute_method() throws Exception {
+    esTester.setProfilingLevel(Profiling.Level.FULL);
     try {
       esTester.client().prepareIndex(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE).execute();
       fail();
index 829b1f22ba216324400f495fe3098ebe14977486..bfaff4bda1d62ae647f35c6980827212f1decdb4 100644 (file)
@@ -28,6 +28,7 @@ import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.utils.Duration;
 import org.sonar.core.rule.RuleDto;
 
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Date;
 
@@ -128,4 +129,26 @@ public class IssueDtoTest {
     assertThat(dto.getLanguage()).isEqualTo("xoo");
   }
 
+  @Test
+  public void set_tags() {
+    IssueDto dto = new IssueDto();
+    assertThat(dto.getTags()).isEmpty();
+    assertThat(dto.getTagsString()).isNull();
+
+    dto.setTags(Arrays.asList("tag1", "tag2", "tag3"));
+    assertThat(dto.getTags()).containsOnly("tag1", "tag2", "tag3");
+    assertThat(dto.getTagsString()).isEqualTo("tag1,tag2,tag3");
+
+    dto.setTags(Arrays.<String>asList());
+    assertThat(dto.getTags()).isEmpty();
+
+    dto.setTagsString("tag1, tag2 ,,tag3");
+    assertThat(dto.getTags()).containsOnly("tag1", "tag2", "tag3");
+
+    dto.setTagsString(null);
+    assertThat(dto.getTags()).isEmpty();
+
+    dto.setTagsString("");
+    assertThat(dto.getTags()).isEmpty();
+  }
 }