@@ -75,96 +75,130 @@ public class SslExample {
7575 @ Test
7676 public void httpTest () throws ArangoException {
7777
78- ArangoConfigure configuration = new ArangoConfigure ();
79- // get host and port from arangodb.properties
80- // configuration.setArangoHost(new ArangoHost("localhost", 8529));
81- configuration .init ();
82-
83- ArangoDriver arangoDriver = new ArangoDriver (configuration );
84-
85- ArangoVersion version = arangoDriver .getVersion ();
86- Assert .assertNotNull (version );
87-
78+ ArangoConfigure configuration = null ;
79+ try {
80+ configuration = new ArangoConfigure ();
81+ // get host and port from arangodb.properties
82+ // configuration.setArangoHost(new ArangoHost("localhost", 8529));
83+ configuration .init ();
84+
85+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
86+
87+ final ArangoVersion version = arangoDriver .getVersion ();
88+ Assert .assertNotNull (version );
89+ } finally {
90+ if (configuration != null ) {
91+ configuration .shutdown ();
92+ }
93+ }
8894 }
8995
9096 @ Test
9197 public void sslConnectionTest () throws ArangoException {
9298 // use HTTPS with java default trust store
93-
94- ArangoConfigure configuration = new ArangoConfigure ();
95- configuration .setArangoHost (new ArangoHost ("www.arangodb.com" , 443 ));
96- configuration .setUseSsl (true );
97- configuration .init ();
98-
99- ArangoDriver arangoDriver = new ArangoDriver (configuration );
100-
101- HttpResponseEntity response = arangoDriver .getHttpManager ().doGet ("/" );
102- Assert .assertEquals (200 , response .getStatusCode ());
99+ ArangoConfigure configuration = null ;
100+ try {
101+ configuration = new ArangoConfigure ();
102+ configuration .setArangoHost (new ArangoHost ("www.arangodb.com" , 443 ));
103+ configuration .setUseSsl (true );
104+ configuration .init ();
105+
106+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
107+
108+ final HttpResponseEntity response = arangoDriver .getHttpManager ().doGet ("/" );
109+ Assert .assertEquals (200 , response .getStatusCode ());
110+ } finally {
111+ if (configuration != null ) {
112+ configuration .shutdown ();
113+ }
114+ }
103115 }
104116
105117 @ Test
106118 public void sslWithSelfSignedCertificateTest () throws ArangoException , KeyManagementException ,
107119 NoSuchAlgorithmException , KeyStoreException , CertificateException , IOException , URISyntaxException {
108120
109- // create a sslContext for the self signed certificate
110- URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
111- SSLContext sslContext = SSLContexts .custom ()
112- .loadTrustMaterial (Paths .get (resource .toURI ()).toFile (), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
113-
114- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
115- configuration .setSslContext (sslContext );
116- configuration .init ();
117-
118- ArangoDriver arangoDriver = new ArangoDriver (configuration );
119-
120- ArangoVersion version = arangoDriver .getVersion ();
121- Assert .assertNotNull (version );
121+ ArangoConfigure configuration = null ;
122+ try {
123+ // create a sslContext for the self signed certificate
124+ final URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
125+ final SSLContext sslContext = SSLContexts .custom ()
126+ .loadTrustMaterial (Paths .get (resource .toURI ()).toFile (), SSL_TRUSTSTORE_PASSWORD .toCharArray ())
127+ .build ();
128+
129+ configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
130+ configuration .setSslContext (sslContext );
131+ configuration .init ();
132+
133+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
134+
135+ final ArangoVersion version = arangoDriver .getVersion ();
136+ Assert .assertNotNull (version );
137+ } finally {
138+ if (configuration != null ) {
139+ configuration .shutdown ();
140+ }
141+ }
122142 }
123143
124144 @ Test
125145 public void sslHandshakeExceptionTest () {
126- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
127- configuration .init ();
146+ ArangoConfigure configuration = null ;
147+ try {
148+ configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
149+ configuration .init ();
128150
129- ArangoDriver arangoDriver = new ArangoDriver (configuration );
151+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
130152
131- try {
132- // java do not trust self signed certificates
153+ try {
154+ // java do not trust self signed certificates
133155
134- arangoDriver .getVersion ();
135- Assert .fail ("this should fail" );
156+ arangoDriver .getVersion ();
157+ Assert .fail ("this should fail" );
136158
137- } catch (ArangoException e ) {
138- Throwable cause = e .getCause ();
139- Assert .assertTrue (cause instanceof javax .net .ssl .SSLHandshakeException );
159+ } catch (final ArangoException e ) {
160+ final Throwable cause = e .getCause ();
161+ Assert .assertTrue (cause instanceof javax .net .ssl .SSLHandshakeException );
162+ }
163+ } finally {
164+ if (configuration != null ) {
165+ configuration .shutdown ();
166+ }
140167 }
141168 }
142169
143170 @ Test
144171 public void sslPeerUnverifiedExceptionTest () throws ArangoException , KeyManagementException ,
145172 NoSuchAlgorithmException , KeyStoreException , CertificateException , IOException , URISyntaxException {
146173
147- // create a sslContext for the self signed certificate
148- URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
149- SSLContext sslContext = SSLContexts .custom ()
150- .loadTrustMaterial (Paths .get (resource .toURI ()).toFile (), SSL_TRUSTSTORE_PASSWORD .toCharArray ()).build ();
151-
152- ArangoConfigure configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
153- // 127.0.0.1 is the wrong name
154- configuration .getArangoHost ().setHost ("127.0.0.1" );
155- configuration .setSslContext (sslContext );
156- configuration .init ();
157-
158- ArangoDriver arangoDriver = new ArangoDriver (configuration );
159-
174+ ArangoConfigure configuration = null ;
160175 try {
161- arangoDriver .getVersion ();
162- Assert .fail ("this should fail" );
163- } catch (ArangoException e ) {
164- Throwable cause = e .getCause ();
165- Assert .assertTrue (cause instanceof javax .net .ssl .SSLPeerUnverifiedException );
176+ // create a sslContext for the self signed certificate
177+ final URL resource = this .getClass ().getResource (SSL_TRUSTSTORE );
178+ final SSLContext sslContext = SSLContexts .custom ()
179+ .loadTrustMaterial (Paths .get (resource .toURI ()).toFile (), SSL_TRUSTSTORE_PASSWORD .toCharArray ())
180+ .build ();
181+
182+ configuration = new ArangoConfigure ("/ssl-arangodb.properties" );
183+ // 127.0.0.1 is the wrong name
184+ configuration .getArangoHost ().setHost ("127.0.0.1" );
185+ configuration .setSslContext (sslContext );
186+ configuration .init ();
187+
188+ final ArangoDriver arangoDriver = new ArangoDriver (configuration );
189+
190+ try {
191+ arangoDriver .getVersion ();
192+ Assert .fail ("this should fail" );
193+ } catch (final ArangoException e ) {
194+ final Throwable cause = e .getCause ();
195+ Assert .assertTrue (cause instanceof javax .net .ssl .SSLPeerUnverifiedException );
196+ }
197+ } finally {
198+ if (configuration != null ) {
199+ configuration .shutdown ();
200+ }
166201 }
167-
168202 }
169203
170204}
0 commit comments