From 123a3853409cbeaf15bd09aa3a38714960141113 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 20 Dec 2017 10:16:35 +0100 Subject: [PATCH] SONAR-10216 fix quality flaws --- .../server/test/index/TestResultSetIterator.java | 5 +++-- .../org/sonar/server/test/index/TestIndexTest.java | 14 +++++++------- .../sonar/server/test/index/TestIndexerTest.java | 9 +++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java index f6e699fbe78..55b595a12f3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java @@ -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 { 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; diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java index a277b42399c..55f4c63621a 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexTest.java @@ -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"))); diff --git a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java index 89370196936..277c003946c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/test/index/TestIndexerTest.java @@ -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 getDocuments() { return es.getDocuments(INDEX_TYPE_TEST); } -- 2.39.5