private void addPeriods(JsonWriter writer) {
writer.name("periods").beginArray();
for (int i=0; i < 3; i ++) {
- writer.beginObject().prop("key", i + 1).prop("text", periods.label(i + 1)).endObject();
+ writer.beginObject().prop("key", (long) i + 1).prop("text", periods.label(i + 1)).endObject();
}
addProjectPeriod(4, writer);
addProjectPeriod(5, writer);
UserSession userSession = UserSession.get();
List<Component> result = Lists.newArrayList();
Collection<String> authorizedProjectKeys = db.authorizationDao().selectAuthorizedRootProjectsKeys(userSession.userId(), UserRole.USER);
- for (String key : componentsByKeys.keySet()) {
- if (authorizedProjectKeys.contains(key)) {
- result.add(componentsByKeys.get(key));
+ for (Map.Entry<String, Component> entry : componentsByKeys.entrySet()) {
+ if (authorizedProjectKeys.contains(entry.getKey())) {
+ result.add(entry.getValue());
}
}
package org.sonar.server.search;
+import org.sonar.server.search.request.ProxyIndexRequestBuilder;
+
import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
return new ProxyDeleteByQueryRequestBuilder(this, profiling).setIndices(indices);
}
- // ****************************************************************************************************************
- // Not yet implemented methods
- // ****************************************************************************************************************
-
- @Override
- public MultiSearchRequestBuilder prepareMultiSearch() {
- throw throwNotYetImplemented();
- }
-
@Override
public IndexRequestBuilder prepareIndex() {
- throw throwNotYetImplemented();
+ return new ProxyIndexRequestBuilder(this, profiling);
}
@Override
public IndexRequestBuilder prepareIndex(String index, String type) {
- throw throwNotYetImplemented();
+ return new ProxyIndexRequestBuilder(this, profiling).setIndex(index).setType(type);
}
@Override
public IndexRequestBuilder prepareIndex(String index, String type, @Nullable String id) {
+ return new ProxyIndexRequestBuilder(this, profiling).setIndex(index).setType(type).setId(id);
+ }
+
+ // ****************************************************************************************************************
+ // Not yet implemented methods
+ // ****************************************************************************************************************
+
+ @Override
+ public MultiSearchRequestBuilder prepareMultiSearch() {
throw throwNotYetImplemented();
}
private void addZeroFacetsForSelectedItems(Request request, String facetName, Set<String> itemsFromFacets, JsonWriter json) {
List<String> requestParams = request.paramAsStrings(facetName);
if (requestParams != null) {
+ System.out.println(requestParams);
+ System.out.println(itemsFromFacets);
for (String param: requestParams) {
if (!itemsFromFacets.contains(param)) {
json.beginObject();
result.assertJson(this.getClass(), "display_facets.json", false);
}
+ @Test
+ public void display_zero_valued_facets_for_selected_items() throws Exception {
+ IssueDto issue = IssueTesting.newDto(rule, file, project)
+ .setIssueCreationDate(DateUtils.parseDate("2014-09-04"))
+ .setIssueUpdateDate(DateUtils.parseDate("2017-12-04"))
+ .setDebt(10L)
+ .setStatus("OPEN")
+ .setKee("82fd47d4-b650-4037-80bc-7b112bd4eac2")
+ .setSeverity("MAJOR");
+ db.issueDao().insert(session, issue);
+ session.commit();
+ tester.get(IssueIndexer.class).indexAll();
+
+ WsTester.Result result = wsTester.newGetRequest(IssuesWs.API_ENDPOINT, SearchAction.SEARCH_ACTION)
+ .setParam("resolved", "false")
+ .setParam("severities", "MAJOR,MINOR")
+ .setParam("languages", "xoo,polop,palap")
+ .setParam(SearchAction.PARAM_FACETS, "statuses,severities,resolutions,projectUuids,rules,componentUuids,assignees,languages,actionPlans")
+ .execute();
+ result.assertJson(this.getClass(), "display_zero_facets.json", false);
+ }
+
@Test
public void hide_rules() throws Exception {
IssueDto issue = IssueTesting.newDto(rule, file, project)
}
}
- @Test
- public void prepare_index_is_not_yet_implemented() throws Exception {
- try {
- searchClient.prepareIndex();
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
- }
-
- try {
- searchClient.prepareIndex("index", "type");
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
- }
-
- try {
- searchClient.prepareIndex("index", "type", "id");
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
- }
- }
-
@Test
public void prepare_update_is_not_yet_implemented() throws Exception {
try {
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 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.search.request;
+
+import org.elasticsearch.action.index.IndexRequestBuilder;
+import org.elasticsearch.common.unit.TimeValue;
+import org.junit.After;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.core.profiling.Profiling;
+import org.sonar.server.search.IndexDefinition;
+import org.sonar.server.search.SearchClient;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+public class ProxyIndexRequestBuilderTest {
+
+ Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.NONE.name()));
+ SearchClient searchClient = new SearchClient(new Settings(), profiling);
+
+ @After
+ public void tearDown() throws Exception {
+ searchClient.stop();
+ }
+
+ @Test
+ public void index_with_index_type_and_id() {
+ try {
+ searchClient.prepareIndex(IndexDefinition.RULE.getIndexName(), IndexDefinition.RULE.getIndexType(), "ruleKey").get();
+
+ // expected to fail because elasticsearch is not correctly configured, but that does not matter
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e.getMessage()).isEqualTo("Fail to execute ES index request for key 'ruleKey' on index 'rules' on type 'rule'");
+ }
+ }
+
+ @Test
+ public void with_profiling_basic() {
+ Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
+ SearchClient searchClient = new SearchClient(new Settings(), profiling);
+
+ try {
+ searchClient.prepareIndex()
+ .setIndex(IndexDefinition.RULE.getIndexName())
+ .setType(IndexDefinition.RULE.getIndexType())
+ .setId("ruleKey")
+ .get();
+
+ // expected to fail because elasticsearch is not correctly configured, but that does not matter
+ fail();
+ } catch (IllegalStateException e) {
+ assertThat(e.getMessage()).isEqualTo("Fail to execute ES index request for key 'ruleKey' on index 'rules' on type 'rule'");
+ }
+
+ // TODO assert profiling
+ searchClient.stop();
+ }
+
+ @Test
+ public void fail_to_get_bad_query() throws Exception {
+ IndexRequestBuilder requestBuilder = searchClient.prepareIndex()
+ .setIndex("unknown")
+ .setType("test")
+ .setId("rule1");
+ try {
+ requestBuilder.get();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'rule1' on index 'unknown' on type 'test'");
+ }
+ }
+
+ @Test
+ public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareIndex().get("1");
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
+ }
+ }
+
+ @Test
+ public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
+ try {
+ searchClient.prepareIndex().get(TimeValue.timeValueMinutes(1));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
+ }
+ }
+
+ @Test
+ public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
+ try {
+ searchClient.prepareIndex().execute();
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");
+ }
+ }
+
+}
--- /dev/null
+{
+ "issues": [
+ {
+ "key": "82fd47d4-b650-4037-80bc-7b112bd4eac2",
+ "component": "MyComponent",
+ "project": "MyProject",
+ "rule": "xoo:x1",
+ "status": "OPEN",
+ "severity": "MAJOR",
+ "debt": "10min",
+ "fUpdateAge": "less than a minute"
+ }
+ ],
+ "facets": [
+ {
+ "property": "statuses",
+ "values": [
+ {
+ "val": "OPEN",
+ "count": 1
+ },
+ {
+ "val": "CONFIRMED",
+ "count": 0
+ },
+ {
+ "val": "REOPENED",
+ "count": 0
+ },
+ {
+ "val": "RESOLVED",
+ "count": 0
+ },
+ {
+ "val": "CLOSED",
+ "count": 0
+ }
+ ]
+ },
+ {
+ "property": "severities",
+ "values": [
+ {
+ "val": "INFO",
+ "count": 0
+ },
+ {
+ "val": "MINOR",
+ "count": 0
+ },
+ {
+ "val": "MAJOR",
+ "count": 1
+ },
+ {
+ "val": "CRITICAL",
+ "count": 0
+ },
+ {
+ "val": "BLOCKER",
+ "count": 0
+ }
+ ]
+ },
+ {
+ "property": "resolutions",
+ "values": [
+ {
+ "val": "",
+ "count": 1
+ },
+ {
+ "val": "FALSE-POSITIVE",
+ "count": 0
+ },
+ {
+ "val": "FIXED",
+ "count": 0
+ },
+ {
+ "val": "REMOVED",
+ "count": 0
+ }
+ ]
+ },
+ {
+ "property": "projectUuids",
+ "values": [
+ {
+ "val": "ABCD",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "property": "rules",
+ "values": [
+ {
+ "val": "xoo:x1",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "property": "componentUuids",
+ "values": [
+ {
+ "val": "BCDE",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "property": "assignees",
+ "values": [
+ {
+ "val": "",
+ "count": 1
+ },
+ {
+ "val": "john",
+ "count": 0
+ }
+ ]
+ },
+ {
+ "property": "languages",
+ "values": [
+ {
+ "val": "xoo",
+ "count": 1
+ },
+ {
+ "val": "polop",
+ "count": 0
+ },
+ {
+ "val": "palap",
+ "count": 0
+ }
+ ]
+ },
+ {
+ "property": "actionPlans",
+ "values": [
+ {
+ "val": "",
+ "count": 1
+ }
+ ]
+ }
+ ]}