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 ;
3638
3739import org .apache .jena .graph .NodeFactory ;
@@ -57,14 +59,14 @@ static void teardown() {
5759 }
5860
5961 @ Test
60- void testOfModelHandler () throws IOException ,
62+ void testOfJenaModelHandler () throws IOException ,
6163 InterruptedException {
6264 final Request request = Request .newBuilder ()
6365 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
6466 .GET ()
6567 .build ();
6668
67- final var response = client .send (request , JenaBodyHandlers .ofModel ())
69+ final var response = client .send (request , JenaBodyHandlers .ofJenaModel ())
6870 .toCompletableFuture ().join ();
6971
7072 assertEquals (200 , response .statusCode ());
@@ -78,15 +80,15 @@ void testOfModelHandler() throws IOException,
7880 }
7981
8082 @ Test
81- void testOfModelHandlerAsync () throws IOException ,
83+ void testOfJenaModelHandlerAsync () throws IOException ,
8284 InterruptedException , ExecutionException {
8385 final Request request = Request .newBuilder ()
8486 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
8587 .header ("Accept" , "text/turtle" )
8688 .GET ()
8789 .build ();
8890
89- final var asyncResponse = client .send (request , JenaBodyHandlers .ofModel ());
91+ final var asyncResponse = client .send (request , JenaBodyHandlers .ofJenaModel ());
9092
9193 final int statusCode = asyncResponse .thenApply (Response ::statusCode ).toCompletableFuture ().join ();
9294 assertEquals (200 , statusCode );
@@ -101,13 +103,13 @@ void testOfModelHandlerAsync() throws IOException,
101103 }
102104
103105 @ Test
104- void testOfModelHandlerWithURL () throws IOException , InterruptedException {
106+ void testOfJenaModelHandlerWithURL () throws IOException , InterruptedException {
105107 final Request request = Request .newBuilder ()
106108 .uri (URI .create (config .get ("rdf_uri" ) + "/example" ))
107109 .GET ()
108110 .build ();
109111
110- final var response = client .send (request , JenaBodyHandlers .ofModel ())
112+ final var response = client .send (request , JenaBodyHandlers .ofJenaModel ())
111113 .toCompletableFuture ().join ();
112114
113115 assertEquals (200 , response .statusCode ());
@@ -120,14 +122,36 @@ void testOfModelHandlerWithURL() throws IOException, InterruptedException {
120122 }
121123
122124 @ Test
123- void testOfDatasetHandler () throws IOException ,
125+ void testOfJenaModelHandlerError () throws IOException ,
126+ InterruptedException {
127+ final Request request = Request .newBuilder ()
128+ .uri (URI .create (config .get ("rdf_uri" ) + "/error" ))
129+ .GET ()
130+ .build ();
131+
132+ final CompletionException completionException = assertThrows (
133+ CompletionException .class ,
134+ () -> client .send (request , JenaBodyHandlers .ofJenaModel ()).toCompletableFuture ().join ()
135+ );
136+
137+ final ClientHttpException httpException = (ClientHttpException ) completionException .getCause ();
138+
139+ assertEquals (429 , httpException .getProblemDetails ().getStatus ());
140+ assertEquals ("Too Many Requests" , httpException .getProblemDetails ().getTitle ());
141+ assertEquals ("Some details" , httpException .getProblemDetails ().getDetails ());
142+ assertEquals ("https://example.org/type" , httpException .getProblemDetails ().getType ().toString ());
143+ assertEquals ("https://example.org/instance" , httpException .getProblemDetails ().getInstance ().toString ());
144+ }
145+
146+ @ Test
147+ void testOfJenaDatasetHandler () throws IOException ,
124148 InterruptedException {
125149 final Request request = Request .newBuilder ()
126150 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
127151 .GET ()
128152 .build ();
129153
130- final var response = client .send (request , JenaBodyHandlers .ofDataset ())
154+ final var response = client .send (request , JenaBodyHandlers .ofJenaDataset ())
131155 .toCompletableFuture ().join ();
132156
133157 assertEquals (200 , response .statusCode ());
@@ -142,13 +166,13 @@ void testOfDatasetHandler() throws IOException,
142166 }
143167
144168 @ Test
145- void testOfDatasetHandlerWithURL () throws IOException , InterruptedException {
169+ void testOfJenaDatasetHandlerWithURL () throws IOException , InterruptedException {
146170 final Request request = Request .newBuilder ()
147171 .uri (URI .create (config .get ("rdf_uri" ) + "/example" ))
148172 .GET ()
149173 .build ();
150174
151- final var response = client .send (request , JenaBodyHandlers .ofDataset ())
175+ final var response = client .send (request , JenaBodyHandlers .ofJenaDataset ())
152176 .toCompletableFuture ().join ();
153177
154178 assertEquals (200 , response .statusCode ());
@@ -163,15 +187,37 @@ void testOfDatasetHandlerWithURL() throws IOException, InterruptedException {
163187 }
164188
165189 @ Test
166- void testOfGraphHandlerAsync () throws IOException ,
190+ void testOfJenaDatasetHandlerError () throws IOException ,
191+ InterruptedException {
192+ final Request request = Request .newBuilder ()
193+ .uri (URI .create (config .get ("rdf_uri" ) + "/error" ))
194+ .GET ()
195+ .build ();
196+
197+ final CompletionException completionException = assertThrows (
198+ CompletionException .class ,
199+ () -> client .send (request , JenaBodyHandlers .ofJenaDataset ()).toCompletableFuture ().join ()
200+ );
201+
202+ final ClientHttpException httpException = (ClientHttpException ) completionException .getCause ();
203+
204+ assertEquals (429 , httpException .getProblemDetails ().getStatus ());
205+ assertEquals ("Too Many Requests" , httpException .getProblemDetails ().getTitle ());
206+ assertEquals ("Some details" , httpException .getProblemDetails ().getDetails ());
207+ assertEquals ("https://example.org/type" , httpException .getProblemDetails ().getType ().toString ());
208+ assertEquals ("https://example.org/instance" , httpException .getProblemDetails ().getInstance ().toString ());
209+ }
210+
211+ @ Test
212+ void testOfJenaGraphHandlerAsync () throws IOException ,
167213 InterruptedException , ExecutionException {
168214 final Request request = Request .newBuilder ()
169215 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
170216 .header ("Accept" , "text/turtle" )
171217 .GET ()
172218 .build ();
173219
174- final var asyncResponse = client .send (request , JenaBodyHandlers .ofGraph ());
220+ final var asyncResponse = client .send (request , JenaBodyHandlers .ofJenaGraph ());
175221
176222 final int statusCode = asyncResponse .thenApply (Response ::statusCode ).toCompletableFuture ().join ();
177223 assertEquals (200 , statusCode );
@@ -186,14 +232,14 @@ void testOfGraphHandlerAsync() throws IOException,
186232 }
187233
188234 @ Test
189- void testOfGraphHandler () throws IOException ,
235+ void testOfJenaGraphHandler () throws IOException ,
190236 InterruptedException {
191237 final Request request = Request .newBuilder ()
192238 .uri (URI .create (config .get ("rdf_uri" ) + "/oneTriple" ))
193239 .GET ()
194240 .build ();
195241
196- final var response = client .send (request , JenaBodyHandlers .ofGraph ())
242+ final var response = client .send (request , JenaBodyHandlers .ofJenaGraph ())
197243 .toCompletableFuture ().join ();
198244
199245 assertEquals (200 , response .statusCode ());
@@ -207,13 +253,13 @@ void testOfGraphHandler() throws IOException,
207253 }
208254
209255 @ Test
210- void testOfGraphHandlerWithURL () throws IOException , InterruptedException {
256+ void testOfJenaGraphHandlerWithURL () throws IOException , InterruptedException {
211257 final Request request = Request .newBuilder ()
212258 .uri (URI .create (config .get ("rdf_uri" ) + "/example" ))
213259 .GET ()
214260 .build ();
215261
216- final var response = client .send (request , JenaBodyHandlers .ofGraph ())
262+ final var response = client .send (request , JenaBodyHandlers .ofJenaGraph ())
217263 .toCompletableFuture ().join ();
218264
219265 assertEquals (200 , response .statusCode ());
@@ -225,4 +271,26 @@ void testOfGraphHandlerWithURL() throws IOException, InterruptedException {
225271 null )
226272 );
227273 }
274+
275+ @ Test
276+ void testOfJenaGraphHandlerError () throws IOException ,
277+ InterruptedException {
278+ final Request request = Request .newBuilder ()
279+ .uri (URI .create (config .get ("rdf_uri" ) + "/error" ))
280+ .GET ()
281+ .build ();
282+
283+ final CompletionException completionException = assertThrows (
284+ CompletionException .class ,
285+ () -> client .send (request , JenaBodyHandlers .ofJenaGraph ()).toCompletableFuture ().join ()
286+ );
287+
288+ final ClientHttpException httpException = (ClientHttpException ) completionException .getCause ();
289+
290+ assertEquals (429 , httpException .getProblemDetails ().getStatus ());
291+ assertEquals ("Too Many Requests" , httpException .getProblemDetails ().getTitle ());
292+ assertEquals ("Some details" , httpException .getProblemDetails ().getDetails ());
293+ assertEquals ("https://example.org/type" , httpException .getProblemDetails ().getType ().toString ());
294+ assertEquals ("https://example.org/instance" , httpException .getProblemDetails ().getInstance ().toString ());
295+ }
228296}
0 commit comments