[TEST] rename restClientTests back to RestClientBuilderTests
This commit is contained in:
parent
24ea585c9e
commit
9ed2d610ec
|
@ -20,18 +20,15 @@
|
||||||
package org.elasticsearch.client;
|
package org.elasticsearch.client;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.generators.RandomInts;
|
import com.carrotsearch.randomizedtesting.generators.RandomInts;
|
||||||
|
import org.apache.http.Header;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.message.BasicHeader;
|
import org.apache.http.message.BasicHeader;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class RestClientTests extends LuceneTestCase {
|
public class RestClientBuilderTests extends LuceneTestCase {
|
||||||
|
|
||||||
public void testBuild() throws IOException {
|
public void testBuild() throws IOException {
|
||||||
try {
|
try {
|
||||||
|
@ -69,12 +66,18 @@ public class RestClientTests extends LuceneTestCase {
|
||||||
assertEquals(e.getMessage(), "host cannot be null");
|
assertEquals(e.getMessage(), "host cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
|
try {
|
||||||
RestClient.builder().setHttpClient(httpClient)
|
RestClient.builder().setDefaultHeaders(null);
|
||||||
.setDefaultHeaders(Collections.singleton(new BasicHeader("header", "value"))).build();
|
|
||||||
fail("should have failed");
|
fail("should have failed");
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(NullPointerException e) {
|
||||||
assertEquals(e.getMessage(), "defaultHeaders need to be set to the HttpClient directly when manually provided");
|
assertEquals(e.getMessage(), "default headers must not be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
RestClient.builder().setDefaultHeaders(new Header[]{null});
|
||||||
|
fail("should have failed");
|
||||||
|
} catch(NullPointerException e) {
|
||||||
|
assertEquals(e.getMessage(), "default header must not be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
RestClient.Builder builder = RestClient.builder();
|
RestClient.Builder builder = RestClient.builder();
|
||||||
|
@ -84,20 +87,17 @@ public class RestClientTests extends LuceneTestCase {
|
||||||
hosts[i] = new HttpHost("localhost", 9200 + i);
|
hosts[i] = new HttpHost("localhost", 9200 + i);
|
||||||
}
|
}
|
||||||
builder.setHosts(hosts);
|
builder.setHosts(hosts);
|
||||||
|
|
||||||
if (random().nextBoolean()) {
|
if (random().nextBoolean()) {
|
||||||
builder.setHttpClient(HttpClientBuilder.create().build());
|
builder.setHttpClient(HttpClientBuilder.create().build());
|
||||||
} else {
|
}
|
||||||
if (random().nextBoolean()) {
|
if (random().nextBoolean()) {
|
||||||
int numHeaders = RandomInts.randomIntBetween(random(), 1, 5);
|
int numHeaders = RandomInts.randomIntBetween(random(), 1, 5);
|
||||||
Collection<BasicHeader> headers = new ArrayList<>(numHeaders);
|
Header[] headers = new Header[numHeaders];
|
||||||
for (int i = 0; i < numHeaders; i++) {
|
for (int i = 0; i < numHeaders; i++) {
|
||||||
headers.add(new BasicHeader("header" + i, "value"));
|
headers[i] = new BasicHeader("header" + i, "value");
|
||||||
}
|
}
|
||||||
builder.setDefaultHeaders(headers);
|
builder.setDefaultHeaders(headers);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (random().nextBoolean()) {
|
if (random().nextBoolean()) {
|
||||||
builder.setMaxRetryTimeout(RandomInts.randomIntBetween(random(), 1, Integer.MAX_VALUE));
|
builder.setMaxRetryTimeout(RandomInts.randomIntBetween(random(), 1, Integer.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
@ -105,33 +105,4 @@ public class RestClientTests extends LuceneTestCase {
|
||||||
assertNotNull(restClient);
|
assertNotNull(restClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetNodes() throws IOException {
|
|
||||||
try (RestClient restClient = RestClient.builder().setHosts(new HttpHost("localhost", 9200)).build()) {
|
|
||||||
try {
|
|
||||||
restClient.setHosts((HttpHost[]) null);
|
|
||||||
fail("setHosts should have failed");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("hosts must not be null nor empty", e.getMessage());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
restClient.setHosts();
|
|
||||||
fail("setHosts should have failed");
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
assertEquals("hosts must not be null nor empty", e.getMessage());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
restClient.setHosts((HttpHost) null);
|
|
||||||
fail("setHosts should have failed");
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
assertEquals("host cannot be null", e.getMessage());
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
restClient.setHosts(new HttpHost("localhost", 9200), null, new HttpHost("localhost", 9201));
|
|
||||||
fail("setHosts should have failed");
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
assertEquals("host cannot be null", e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue