2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 package org.sonar.server.search.request;
23 import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
24 import org.elasticsearch.common.unit.TimeValue;
25 import org.junit.After;
26 import org.junit.Test;
27 import org.sonar.api.config.Settings;
28 import org.sonar.core.profiling.Profiling;
29 import org.sonar.server.search.SearchClient;
31 import static org.fest.assertions.Assertions.assertThat;
32 import static org.fest.assertions.Fail.fail;
34 public class ProxyClusterStateRequestBuilderText {
36 Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.FULL.name()));
37 SearchClient searchClient = new SearchClient(new Settings(), profiling);
40 public void tearDown() throws Exception {
47 ClusterStateRequestBuilder requestBuilder = searchClient.prepareState();
50 // expected to fail because elasticsearch is not correctly configured, but that does not matter
52 } catch (IllegalStateException e) {
53 assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster state request");
58 public void to_string() {
59 assertThat(searchClient.prepareState().setIndices("rules").toString()).isEqualTo("ES cluster state request on indices 'rules'");
60 assertThat(searchClient.prepareState().toString()).isEqualTo("ES cluster state request");
64 public void with_profiling_basic() {
65 Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
66 SearchClient searchClient = new SearchClient(new Settings(), profiling);
69 ClusterStateRequestBuilder requestBuilder = searchClient.prepareState();
72 // expected to fail because elasticsearch is not correctly configured, but that does not matter
74 } catch (IllegalStateException e) {
75 assertThat(e.getMessage()).isEqualTo("Fail to execute ES cluster state request");
78 // TODO assert profiling
83 public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
85 searchClient.prepareState().get("1");
87 } catch (Exception e) {
88 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
93 public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
95 searchClient.prepareState().get(TimeValue.timeValueMinutes(1));
97 } catch (Exception e) {
98 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
103 public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
105 searchClient.prepareState().execute();
107 } catch (Exception e) {
108 assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");