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.indices.create.CreateIndexRequestBuilder;
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 ProxyCreateIndexRequestBuilderText {
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 {
45 public void create_index() {
47 CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
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 create index 'new'");
58 public void to_string() {
59 assertThat(searchClient.prepareCreate("new").toString()).isEqualTo("ES create index 'new'");
63 public void with_profiling_basic() {
64 Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
65 SearchClient searchClient = new SearchClient(new Settings(), profiling);
68 CreateIndexRequestBuilder requestBuilder = searchClient.prepareCreate("new");
71 // expected to fail because elasticsearch is not correctly configured, but that does not matter
73 } catch (IllegalStateException e) {
74 assertThat(e.getMessage()).isEqualTo("Fail to execute ES create index 'new'");
77 // TODO assert profiling
82 public void get_with_string_timeout_is_not_yet_implemented() throws Exception {
84 searchClient.prepareCreate("new").get("1");
86 } catch (Exception e) {
87 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
92 public void get_with_time_value_timeout_is_not_yet_implemented() throws Exception {
94 searchClient.prepareCreate("new").get(TimeValue.timeValueMinutes(1));
96 } catch (Exception e) {
97 assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented");
102 public void execute_should_throw_an_unsupported_operation_exception() throws Exception {
104 searchClient.prepareCreate("new").execute();
106 } catch (Exception e) {
107 assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous");