]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10216 fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 20 Dec 2017 09:16:35 +0000 (10:16 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 20 Dec 2017 10:42:02 +0000 (11:42 +0100)
server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java
server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java

index f6e699fbe782470770202799b66cd01d67ea834f..55b595a12f334526fe88e835ad27f357dd75ab08 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Date;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.elasticsearch.action.update.UpdateRequest;
+import org.elasticsearch.common.xcontent.XContentType;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.DbClient;
@@ -134,8 +135,8 @@ public class TestResultSetIterator extends ResultSetIterator<Row> {
       byte[] jsonDoc = bytes.toByteArray();
       UpdateRequest updateRequest = new UpdateRequest(INDEX_TYPE_TEST.getIndex(), INDEX_TYPE_TEST.getType(), test.getUuid())
         .routing(projectUuid)
-        .doc(jsonDoc)
-        .upsert(jsonDoc);
+        .doc(jsonDoc, XContentType.JSON)
+        .upsert(jsonDoc, XContentType.JSON);
       result.getUpdateRequests().add(updateRequest);
     }
     return result;
index a277b42399c741b31e9cea107ec33057a422f8c0..55f4c63621a844822217479e80cd118cfc568c06 100644 (file)
@@ -37,10 +37,10 @@ public class TestIndexTest {
   @Rule
   public EsTester es = new EsTester(new TestIndexDefinition(new MapSettings().asConfig()));
 
-  TestIndex underTest = new TestIndex(es.client(), System2.INSTANCE);
+  private TestIndex underTest = new TestIndex(es.client(), System2.INSTANCE);
 
   @Test
-  public void coveredFiles() throws Exception {
+  public void coveredFiles() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
@@ -53,7 +53,7 @@ public class TestIndexTest {
   }
 
   @Test
-  public void searchByTestFileUuid() throws Exception {
+  public void searchByTestFileUuid() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")),
@@ -66,7 +66,7 @@ public class TestIndexTest {
   }
 
   @Test
-  public void searchBySourceFileUuidAndLineNumber() throws Exception {
+  public void searchBySourceFileUuidAndLineNumber() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("10"), newCoveredFileDoc("11"), newCoveredFileDoc("12")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
@@ -79,7 +79,7 @@ public class TestIndexTest {
   }
 
   @Test
-  public void searchByTestUuid() throws Exception {
+  public void searchByTestUuid() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
@@ -97,7 +97,7 @@ public class TestIndexTest {
   }
 
   @Test
-  public void getNullableByTestUuid() throws Exception {
+  public void getNullableByTestUuid() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
@@ -124,7 +124,7 @@ public class TestIndexTest {
   }
 
   @Test
-  public void searchByTestUuid_with_SearchOptions() throws Exception {
+  public void searchByTestUuid_with_SearchOptions() {
     es.putDocuments(INDEX_TYPE_TEST,
       newTestDoc("1", "TESTFILE1", newCoveredFileDoc("3"), newCoveredFileDoc("4"), newCoveredFileDoc("5")),
       newTestDoc("2", "TESTFILE1", newCoveredFileDoc("5"), newCoveredFileDoc("6"), newCoveredFileDoc("7")));
index 893701969368cc9d351ed3057c32dbdad3ea9fd5..277c003946c22b1cbc03a65076b383533d539710 100644 (file)
@@ -23,7 +23,7 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import org.apache.commons.io.IOUtils;
-import org.elasticsearch.action.search.SearchRequestBuilder;
+import org.elasticsearch.common.xcontent.XContentType;
 import org.elasticsearch.search.SearchHit;
 import org.junit.Rule;
 import org.junit.Test;
@@ -137,18 +137,15 @@ public class TestIndexerTest {
   }
 
   private void indexTest(String projectUuid, String fileUuid, String testName, String uuid) throws IOException {
+    String json = IOUtils.toString(getClass().getResource(format("%s/%s_%s_%s.json", getClass().getSimpleName(), projectUuid, fileUuid, testName)));
     es.client().prepareIndex(INDEX_TYPE_TEST)
       .setId(uuid)
       .setRouting(projectUuid)
-      .setSource(IOUtils.toString(getClass().getResource(format("%s/%s_%s_%s.json", getClass().getSimpleName(), projectUuid, fileUuid, testName))))
+      .setSource(json, XContentType.JSON)
       .setRefreshPolicy(REFRESH_IMMEDIATE)
       .get();
   }
 
-  private SearchRequestBuilder prepareSearch() {
-    return es.client().prepareSearch(INDEX_TYPE_TEST);
-  }
-
   private List<SearchHit> getDocuments() {
     return es.getDocuments(INDEX_TYPE_TEST);
   }