Skip to content

Commit d7b86f7

Browse files
committed
test fixes
1 parent 03828da commit d7b86f7

File tree

3 files changed

+28
-309
lines changed

3 files changed

+28
-309
lines changed

java-client/src/main/java/co/elastic/clients/transport/rest_client/RestClientOptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ public Function<List<String>, Boolean> onWarnings() {
104104

105105
@Override
106106
public void updateToken(String token) {
107-
// TODO not many choices here
108-
throw new UnsupportedOperationException("Operation unsupported, use rest5 client");
107+
throw new UnsupportedOperationException("Operation unsupported in the legacy client, use rest5 client");
109108
}
110109

111110
@Override

java-client/src/test/java/co/elastic/clients/elasticsearch/_helpers/ClientBuildersTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import co.elastic.clients.elasticsearch.ElasticsearchClient;
2323
import co.elastic.clients.elasticsearch._helpers.builders.ElasticsearchClientBuilder;
24+
import co.elastic.clients.transport.rest5_client.Rest5ClientOptions;
25+
import co.elastic.clients.transport.rest5_client.Rest5ClientTransport;
2426
import co.elastic.clients.transport.rest_client.RestClientOptions;
2527
import co.elastic.clients.transport.rest_client.RestClientTransport;
2628
import org.elasticsearch.client.RequestOptions;
@@ -31,12 +33,13 @@
3133
import java.net.URISyntaxException;
3234
import java.security.NoSuchAlgorithmException;
3335

36+
import static org.junit.Assert.assertThrows;
3437
import static org.junit.Assert.assertTrue;
3538

3639
public class ClientBuildersTest {
3740

3841
@Test
39-
public void build() throws IOException, URISyntaxException, NoSuchAlgorithmException {
42+
public void buildLegacy() throws IOException, URISyntaxException, NoSuchAlgorithmException {
4043

4144
// create client with helper
4245
ElasticsearchClient client = new ElasticsearchClientBuilder()
@@ -54,7 +57,29 @@ public void build() throws IOException, URISyntaxException, NoSuchAlgorithmExcep
5457
assertTrue(client._transportOptions().keepResponseBodyOnException());
5558
assertTrue(client._transportOptions().headers().size() == 3);
5659

57-
//assertTrue(client._transport().options().keepResponseBodyOnException()); TODO ?
60+
// token update utility
61+
ElasticsearchClient finalClient = client;
62+
assertThrows(UnsupportedOperationException.class, () -> finalClient._transportOptions().updateToken("token"));
63+
}
64+
65+
@Test
66+
public void buildRest5() throws IOException, URISyntaxException, NoSuchAlgorithmException {
67+
68+
// create client with helper
69+
ElasticsearchClient client = new co.elastic.clients.elasticsearch._helpers.builders.rest5_client.ElasticsearchClientBuilder()
70+
.host("url")
71+
.usernameAndPassword("elastic", "changeme")
72+
.sslContext(SSLContext.getDefault())
73+
.build();
74+
75+
Rest5ClientOptions options = new Rest5ClientOptions(co.elastic.clients.transport.rest5_client.low_level.RequestOptions.DEFAULT, true);
76+
77+
client = client.withTransportOptions(options);
78+
79+
// checking options correctness
80+
assertTrue(client._transport().getClass().equals(Rest5ClientTransport.class));
81+
assertTrue(client._transportOptions().keepResponseBodyOnException());
82+
assertTrue(client._transportOptions().headers().size() == 3);
5883

5984
// token update utility
6085

java-client/src/test/java/co/elastic/clients/elasticsearch/model/BehaviorsTest2.java

Lines changed: 0 additions & 305 deletions
This file was deleted.

0 commit comments

Comments
 (0)