2222
2323import static org .junit .jupiter .api .Assertions .*;
2424
25+ import com .inrupt .client .ClientHttpException ;
2526import com .inrupt .client .Request ;
2627import com .inrupt .client .Response ;
2728import com .inrupt .client .spi .HttpService ;
3233import java .net .URI ;
3334import java .util .HashMap ;
3435import java .util .Map ;
36+ import java .util .concurrent .CompletionException ;
3537import java .util .concurrent .ExecutionException ;
3638import java .util .concurrent .TimeoutException ;
3739
@@ -61,14 +63,14 @@ static void teardown() {
6163 }
6264
6365 @ Test
64- void testOfModelHandlerAsync () throws IOException ,
66+ void testOfRDF4JModelHandlerAsync () throws IOException ,
6567 InterruptedException , ExecutionException , TimeoutException {
6668 final Request request = Request .newBuilder ()
6769 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
6870 .GET ()
6971 .build ();
7072
71- final Response <Model > res = client .send (request , RDF4JBodyHandlers .ofModel ()).toCompletableFuture ().join ();
73+ final Response <Model > res = client .send (request , RDF4JBodyHandlers .ofRDF4JModel ()).toCompletableFuture ().join ();
7274
7375 final int statusCode = res .statusCode ();
7476 final Model responseBody = res .body ();
@@ -84,14 +86,14 @@ void testOfModelHandlerAsync() throws IOException,
8486 }
8587
8688 @ Test
87- void testOfModelHandler () throws IOException ,
89+ void testOfRDF4JModelHandler () throws IOException ,
8890 InterruptedException , ExecutionException , TimeoutException {
8991 final Request request = Request .newBuilder ()
9092 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
9193 .GET ()
9294 .build ();
9395
94- final Response <Model > response = client .send (request , RDF4JBodyHandlers .ofModel ())
96+ final Response <Model > response = client .send (request , RDF4JBodyHandlers .ofRDF4JModel ())
9597 .toCompletableFuture ().join ();
9698
9799 assertEquals (200 , response .statusCode ());
@@ -106,13 +108,13 @@ void testOfModelHandler() throws IOException,
106108 }
107109
108110 @ Test
109- void testOfModelHandlerWithURL () throws IOException , InterruptedException {
111+ void testOfRDF4JModelHandlerWithURL () throws IOException , InterruptedException {
110112 final Request request = Request .newBuilder ()
111113 .uri (URI .create (config .get ("rdf_uri" ) + "/example" ))
112114 .GET ()
113115 .build ();
114116
115- final Response <Model > response = client .send (request , RDF4JBodyHandlers .ofModel ())
117+ final Response <Model > response = client .send (request , RDF4JBodyHandlers .ofRDF4JModel ())
116118 .toCompletableFuture ().join ();
117119
118120 assertEquals (200 , response .statusCode ());
@@ -128,14 +130,36 @@ void testOfModelHandlerWithURL() throws IOException, InterruptedException {
128130 }
129131
130132 @ Test
131- void testOfRepositoryHandlerAsync () throws IOException ,
133+ void testOfRDF4JModelHandlerError () throws IOException ,
134+ InterruptedException , ExecutionException , TimeoutException {
135+ final Request request = Request .newBuilder ()
136+ .uri (URI .create (config .get ("rdf_uri" ) + "/error" ))
137+ .GET ()
138+ .build ();
139+
140+ final CompletionException completionException = assertThrows (
141+ CompletionException .class ,
142+ () -> client .send (request , RDF4JBodyHandlers .ofRDF4JModel ()).toCompletableFuture ().join ()
143+ );
144+
145+ final ClientHttpException httpException = (ClientHttpException ) completionException .getCause ();
146+
147+ assertEquals (429 , httpException .getProblemDetails ().getStatus ());
148+ assertEquals ("Too Many Requests" , httpException .getProblemDetails ().getTitle ());
149+ assertEquals ("Some details" , httpException .getProblemDetails ().getDetails ());
150+ assertEquals ("https://example.org/type" , httpException .getProblemDetails ().getType ().toString ());
151+ assertEquals ("https://example.org/instance" , httpException .getProblemDetails ().getInstance ().toString ());
152+ }
153+
154+ @ Test
155+ void testOfRDF4JRepositoryHandlerAsync () throws IOException ,
132156 InterruptedException , ExecutionException , TimeoutException {
133157 final Request request = Request .newBuilder ()
134158 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
135159 .GET ()
136160 .build ();
137161
138- final Response <Repository > res = client .send (request , RDF4JBodyHandlers .ofRepository ())
162+ final Response <Repository > res = client .send (request , RDF4JBodyHandlers .ofRDF4JRepository ())
139163 .toCompletableFuture ().join ();
140164
141165 final int statusCode = res .statusCode ();
@@ -155,14 +179,14 @@ void testOfRepositoryHandlerAsync() throws IOException,
155179 }
156180
157181 @ Test
158- void testOfRepositoryHandler () throws IOException ,
182+ void testOfRDF4JRepositoryHandler () throws IOException ,
159183 InterruptedException , ExecutionException , TimeoutException {
160184 final Request request = Request .newBuilder ()
161185 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
162186 .GET ()
163187 .build ();
164188
165- final Response <Repository > response = client .send (request , RDF4JBodyHandlers .ofRepository ())
189+ final Response <Repository > response = client .send (request , RDF4JBodyHandlers .ofRDF4JRepository ())
166190 .toCompletableFuture ().join ();
167191 assertEquals (200 , response .statusCode ());
168192
@@ -180,13 +204,13 @@ void testOfRepositoryHandler() throws IOException,
180204 }
181205
182206 @ Test
183- void testOfRepositoryHandlerWithURL () throws IOException , InterruptedException {
207+ void testOfRDF4JRepositoryHandlerWithURL () throws IOException , InterruptedException {
184208 final Request request = Request .newBuilder ()
185209 .uri (URI .create (config .get ("rdf_uri" ) + "/example" ))
186210 .GET ()
187211 .build ();
188212
189- final Response <Repository > response = client .send (request , RDF4JBodyHandlers .ofRepository ())
213+ final Response <Repository > response = client .send (request , RDF4JBodyHandlers .ofRDF4JRepository ())
190214 .toCompletableFuture ().join ();
191215 assertEquals (200 , response .statusCode ());
192216
@@ -202,4 +226,26 @@ void testOfRepositoryHandlerWithURL() throws IOException, InterruptedException {
202226 );
203227 }
204228 }
229+
230+ @ Test
231+ void testOfRDF4JRepositoryHandlerError () throws IOException ,
232+ InterruptedException , ExecutionException , TimeoutException {
233+ final Request request = Request .newBuilder ()
234+ .uri (URI .create (config .get ("rdf_uri" ) + "/error" ))
235+ .GET ()
236+ .build ();
237+
238+ final CompletionException completionException = assertThrows (
239+ CompletionException .class ,
240+ () -> client .send (request , RDF4JBodyHandlers .ofRDF4JRepository ()).toCompletableFuture ().join ()
241+ );
242+
243+ final ClientHttpException httpException = (ClientHttpException ) completionException .getCause ();
244+
245+ assertEquals (429 , httpException .getProblemDetails ().getStatus ());
246+ assertEquals ("Too Many Requests" , httpException .getProblemDetails ().getTitle ());
247+ assertEquals ("Some details" , httpException .getProblemDetails ().getDetails ());
248+ assertEquals ("https://example.org/type" , httpException .getProblemDetails ().getType ().toString ());
249+ assertEquals ("https://example.org/instance" , httpException .getProblemDetails ().getInstance ().toString ());
250+ }
205251}
0 commit comments