2121
2222import co .elastic .clients .elasticsearch .ElasticsearchClient ;
2323import 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 ;
2426import co .elastic .clients .transport .rest_client .RestClientOptions ;
2527import co .elastic .clients .transport .rest_client .RestClientTransport ;
2628import org .elasticsearch .client .RequestOptions ;
3133import java .net .URISyntaxException ;
3234import java .security .NoSuchAlgorithmException ;
3335
36+ import static org .junit .Assert .assertThrows ;
3437import static org .junit .Assert .assertTrue ;
3538
3639public 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
0 commit comments