From 269c767e84f04d5c92df4bc6b406bd209e585256 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 16 May 2016 14:25:52 +0200 Subject: [PATCH] Remove dead code --- .../sonar/server/search/ws/BaseMapping.java | 53 ------ .../server/search/ws/SearchOptionsTest.java | 159 ------------------ .../search/ESNodeTest/data-es-clean.zip | Bin 11896 -> 0 bytes .../search/ESNodeTest/data-es-corrupt.zip | Bin 11556 -> 0 bytes 4 files changed, 212 deletions(-) delete mode 100644 server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/search/ESNodeTest/data-es-clean.zip delete mode 100644 server/sonar-server/src/test/resources/org/sonar/server/search/ESNodeTest/data-es-corrupt.zip diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/ws/BaseMapping.java b/server/sonar-server/src/main/java/org/sonar/server/search/ws/BaseMapping.java index 3438f6a7f9f..3009997005d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/ws/BaseMapping.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/ws/BaseMapping.java @@ -22,7 +22,6 @@ package org.sonar.server.search.ws; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; import java.util.Arrays; -import java.util.List; import java.util.Set; import javax.annotation.Nullable; import org.sonar.api.server.ServerSide; @@ -52,18 +51,6 @@ public abstract class BaseMapping { return mappers.keySet(); } - public org.sonar.server.es.SearchOptions newQueryOptions(SearchOptions options) { - org.sonar.server.es.SearchOptions result = new org.sonar.server.es.SearchOptions(); - result.setPage(options.page(), options.pageSize()); - List optionFields = options.fields(); - if (optionFields != null) { - for (String optionField : optionFields) { - result.addFields(indexFieldsByWsFields.get(optionField)); - } - } - return result; - } - /** * Write only requested document fields */ @@ -89,18 +76,10 @@ public abstract class BaseMapping { return map(key, new IndexStringMapper(key, indexKey)); } - protected BaseMapping mapBoolean(String key, String indexKey) { - return map(key, new IndexBooleanMapper(key, indexKey)); - } - protected BaseMapping mapDateTime(String key, String indexKey) { return map(key, new IndexDatetimeMapper(key, indexKey)); } - protected BaseMapping mapArray(String key, String indexKey) { - return map(key, new IndexArrayMapper(key, indexKey)); - } - protected BaseMapping map(String key, Mapper mapper) { mappers.put(key, mapper); if (mapper instanceof IndexMapper) { @@ -148,38 +127,6 @@ public abstract class BaseMapping { } } - public static class IndexBooleanMapper extends IndexMapper { - private final String key; - - public IndexBooleanMapper(String key, String indexKey) { - super(indexKey); - this.key = key; - } - - @Override - public void write(JsonWriter json, DOC doc, CTX context) { - Boolean val = doc.getNullableField(indexFields[0]); - json.prop(key, val != null ? val.booleanValue() : null); - } - } - - public static class IndexArrayMapper extends IndexMapper { - private final String key; - - public IndexArrayMapper(String key, String indexKey) { - super(indexKey); - this.key = key; - } - - @Override - public void write(JsonWriter json, DOC doc, CTX context) { - Iterable values = doc.getNullableField(indexFields[0]); - if (values != null) { - json.name(key).beginArray().values(values).endArray(); - } - } - } - public static class IndexDatetimeMapper extends IndexMapper { private final String key; diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java deleted file mode 100644 index 6bac7a5230c..00000000000 --- a/server/sonar-server/src/test/java/org/sonar/server/search/ws/SearchOptionsTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact AT sonarsource DOT com - * - * This program 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. - * - * This program 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.search.ws; - -import com.google.common.collect.Lists; -import java.io.StringWriter; -import org.junit.Test; -import org.sonar.api.server.ws.RequestHandler; -import org.sonar.api.server.ws.WebService; -import org.sonar.api.server.ws.WebService.Param; -import org.sonar.api.server.ws.internal.SimpleGetRequest; -import org.sonar.api.utils.text.JsonWriter; -import org.sonar.server.search.QueryContext; -import org.sonar.server.search.Result; -import org.sonar.test.JsonAssert; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SearchOptionsTest { - - @Test - public void create_from_http_request() { - SimpleGetRequest request = new SimpleGetRequest(); - request.setParam(Param.PAGE, "3"); - request.setParam(Param.PAGE_SIZE, "10"); - request.setParam(Param.FIELDS, "name,repo"); - request.setParam("severities", "BLOCKER"); - - SearchOptions options = SearchOptions.create(request); - - assertThat(options.fields()).containsOnly("name", "repo"); - assertThat(options.page()).isEqualTo(3); - assertThat(options.pageSize()).isEqualTo(10); - } - - @Test - public void hasField() { - SimpleGetRequest request = new SimpleGetRequest(); - request.setParam(Param.PAGE, "3"); - request.setParam(Param.PAGE_SIZE, "10"); - request.setParam(Param.FIELDS, "name,repo"); - SearchOptions options = SearchOptions.create(request); - - assertThat(options.hasField("repo")).isTrue(); - assertThat(options.hasField("severity")).isFalse(); - } - - @Test - public void hasField_always_true_by_default() { - SimpleGetRequest request = new SimpleGetRequest(); - request.setParam(Param.PAGE, "3"); - request.setParam(Param.PAGE_SIZE, "10"); - SearchOptions options = SearchOptions.create(request); - - assertThat(options.hasField("repo")).isTrue(); - } - - @Test - public void hasField_no_if_empty_value() { - SimpleGetRequest request = new SimpleGetRequest(); - request.setParam(Param.PAGE, "3"); - request.setParam(Param.PAGE_SIZE, "10"); - request.setParam(Param.FIELDS, ""); - SearchOptions options = SearchOptions.create(request); - - assertThat(options.hasField("repo")).isFalse(); - } - - @Test - public void write_statistics_to_json_response() { - SimpleGetRequest request = new SimpleGetRequest(); - request.setParam(Param.PAGE, "3"); - request.setParam(Param.PAGE_SIZE, "10"); - request.setParam(Param.FIELDS, "name,repo"); - request.setParam("severities", "BLOCKER"); - - SearchOptions options = SearchOptions.create(request); - StringWriter json = new StringWriter(); - JsonWriter jsonWriter = JsonWriter.of(json).beginObject(); - Result result = mock(Result.class); - when(result.getTotal()).thenReturn(42L); - options.writeStatistics(jsonWriter, result); - jsonWriter.endObject().close(); - - JsonAssert.assertJson(json.toString()).isSimilarTo("{\"total\": 42, \"p\": 3, \"ps\": 10}"); - } - - @Test - public void defineFieldsParam() { - WebService.Context context = new WebService.Context(); - new WebService() { - @Override - public void define(Context context) { - NewController newController = context.createController("api/foo"); - NewAction action = newController - .createAction("search") - .setSince("5.3") - .setDescription("Search Description") - .setPost(true) - .setHandler(mock(RequestHandler.class)); - SearchOptions.defineFieldsParam(action, Lists.newArrayList("name", "lang", "severity")); - newController.done(); - } - }.define(context); - - WebService.Action searchAction = context.controller("api/foo").action("search"); - Param param = searchAction.param(Param.FIELDS); - assertThat(param).isNotNull(); - assertThat(param.possibleValues()).containsOnly("name", "lang", "severity"); - assertThat(param.exampleValue()).isEqualTo("name,lang"); - } - - @Test - public void definePageParams() { - WebService.Context context = new WebService.Context(); - new WebService() { - @Override - public void define(Context context) { - NewController newController = context.createController("api/foo"); - NewAction action = newController - .createAction("search") - .setSince("5.3") - .setDescription("Search Description") - .setPost(true) - .setHandler(mock(RequestHandler.class)); - SearchOptions.definePageParams(action); - newController.done(); - } - }.define(context); - - WebService.Action searchAction = context.controller("api/foo").action("search"); - Param page = searchAction.param(Param.PAGE); - assertThat(page).isNotNull(); - assertThat(page.defaultValue()).isEqualTo("1"); - Param pageSize = searchAction.param(Param.PAGE_SIZE); - assertThat(pageSize).isNotNull(); - assertThat(pageSize.defaultValue()).isEqualTo("" + QueryContext.DEFAULT_LIMIT); - - } -} diff --git a/server/sonar-server/src/test/resources/org/sonar/server/search/ESNodeTest/data-es-clean.zip b/server/sonar-server/src/test/resources/org/sonar/server/search/ESNodeTest/data-es-clean.zip deleted file mode 100644 index 66aaf5ec1249a86e0812aa47b625b7acd167ae4f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11896 zcmd5>drVVT7;oiiVaj+4hGl}d@shp*b<3g^dDKQy%R{3XkCwuyScJk9%r-F0W#Au< zO$=&`S-^pWxTq|;EFoERDk22j%$AVA#=^2?sLfpB9**4$oc7%7ZTU`bYulz!67KJJ zzVm&*-@WJiG-@ATk$`^19@wyL;mgtwksw51t}&I>)i&r1X@$Fk1){!TE&cgZ7%tG* zy)J}tovEhWU?#Xal;dhK!S&Ic*O!><%j&s<2p0rWZ+7tO9Klpp*XYWsQzh&@xjgZ+ z?&)_Qo!-;Yd%9zH$CLhnl)+wwZ1Y1+j>>3K=IK;M%f+do_k5_`3kZy>NV=6o?e#0v z$Np}{a4w|ER9>Yg+SfRTIQttZM8hG1eO?d3BgtGc5Ro{SQZnF$Qc0DvliNS5)o7B` zsY#q z_2!M01{0h3pZWRu&HjOcUIAqi`ODC%&B^m3=@OP-bU(AoIWoo7y+J$-7IcBENw z>{j)Ij!&R;INOJT4B!8D!J`7 z6}Za!x-yfwx~7sqo0+80hy$+z=_YnE?3)zK3?u|0z|26B<|Z?+0(+4eNYdP61_;-q zW`GvqAv0jpd#4#l(vVOIlms&a3>tB`*9@ctA;8Q)>Mk>|0(+4eNZn)x2-l-#fEM8) zGhowurx{4yX9gJb^DzUN%gsRME;FzKdyyH)+++p_*P~{D7U3Z?VAFf28OR))0rxQt z_GExT!^}WmTKdRP9?>seopIapNVLkLYB)G?_mBEJqGK6#<#z^B`ciTuE);2o^9Bko zX{jUiNaBt{ZLgtOnEi5H-q7HHWixfYqfeWYyG8PB>JYWl;Xw*^_>jBYV&v|!7%Q+B zS&ZCG7K3oPEhhc>bRy6qJY+F!dR`VIi$DIjIP(3O1p#f{cX8ZRod~&Oi{Wl^z$^xX z=CYXdXL@n=I}wSX)(3IdKuiK_N4AUI;m*BXT_-#CSggI_Ty?EVr@CN%S7|I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