21
21
22
22
import co .elastic .clients .elasticsearch .ElasticsearchClient ;
23
23
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 ;
24
26
import co .elastic .clients .transport .rest_client .RestClientOptions ;
25
27
import co .elastic .clients .transport .rest_client .RestClientTransport ;
26
28
import org .elasticsearch .client .RequestOptions ;
31
33
import java .net .URISyntaxException ;
32
34
import java .security .NoSuchAlgorithmException ;
33
35
36
+ import static org .junit .Assert .assertThrows ;
34
37
import static org .junit .Assert .assertTrue ;
35
38
36
39
public class ClientBuildersTest {
37
40
38
41
@ Test
39
- public void build () throws IOException , URISyntaxException , NoSuchAlgorithmException {
42
+ public void buildLegacy () throws IOException , URISyntaxException , NoSuchAlgorithmException {
40
43
41
44
// create client with helper
42
45
ElasticsearchClient client = new ElasticsearchClientBuilder ()
@@ -54,7 +57,29 @@ public void build() throws IOException, URISyntaxException, NoSuchAlgorithmExcep
54
57
assertTrue (client ._transportOptions ().keepResponseBodyOnException ());
55
58
assertTrue (client ._transportOptions ().headers ().size () == 3 );
56
59
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 );
58
83
59
84
// token update utility
60
85
0 commit comments