@@ -65,11 +65,13 @@ class AccessGrantClientTest {
6565 private static final URI ACCESS_REQUEST = URI .create ("http://www.w3.org/ns/solid/vc#SolidAccessRequest" );
6666
6767 private static final MockAccessGrantServer mockServer = new MockAccessGrantServer ();
68+ private static AccessGrantClient agClient ;
6869 private static URI baseUri ;
6970
7071 @ BeforeAll
7172 static void setup () {
7273 baseUri = URI .create (mockServer .start ());
74+ agClient = new AccessGrantClient (baseUri );
7375 }
7476
7577 @ AfterAll
@@ -93,8 +95,7 @@ void testFetch1() {
9395 claims .put ("azp" , AZP );
9496 final String token = generateIdToken (claims );
9597 final URI uri = URIBuilder .newBuilder (baseUri ).path ("access-grant-1" ).build ();
96- final AccessGrantClient client = new AccessGrantClient (baseUri )
97- .session (OpenIdSession .ofIdToken (token ));
98+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
9899 final AccessGrant grant = client .fetch (uri ).toCompletableFuture ().join ();
99100
100101 assertEquals (uri , grant .getIdentifier ());
@@ -116,8 +117,7 @@ void testFetch2() {
116117 claims .put ("azp" , AZP );
117118 final String token = generateIdToken (claims );
118119 final URI uri = URIBuilder .newBuilder (baseUri ).path ("access-grant-2" ).build ();
119- final AccessGrantClient client = new AccessGrantClient (baseUri )
120- .session (OpenIdSession .ofIdToken (token ));
120+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
121121 final AccessGrant grant = client .fetch (uri ).toCompletableFuture ().join ();
122122
123123 assertEquals (uri , grant .getIdentifier ());
@@ -143,8 +143,7 @@ void testFetch6() {
143143 claims .put ("azp" , AZP );
144144 final String token = generateIdToken (claims );
145145 final URI uri = URIBuilder .newBuilder (baseUri ).path ("access-grant-6" ).build ();
146- final AccessGrantClient client = new AccessGrantClient (baseUri )
147- .session (OpenIdSession .ofIdToken (token ));
146+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
148147 final AccessGrant grant = client .fetch (uri ).toCompletableFuture ().join ();
149148
150149 assertEquals (uri , grant .getIdentifier ());
@@ -168,35 +167,32 @@ void testNotAccessGrant() {
168167 claims .put ("azp" , AZP );
169168 final String token = generateIdToken (claims );
170169 final URI uri = URIBuilder .newBuilder (baseUri ).path ("vc-3" ).build ();
171- final AccessGrantClient client = new AccessGrantClient (baseUri )
172- .session (OpenIdSession .ofIdToken (token ));
170+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
173171 final CompletionException err = assertThrows (CompletionException .class ,
174172 client .fetch (uri ).toCompletableFuture ()::join );
175173 }
176174
177175 @ Test
178176 void testFetchInvalid () {
179177 final URI uri = URIBuilder .newBuilder (baseUri ).path (".well-known/vc-configuration" ).build ();
180- final AccessGrantClient client = new AccessGrantClient (baseUri );
181178 final CompletionException err = assertThrows (CompletionException .class ,
182- client .fetch (uri ).toCompletableFuture ()::join );
179+ agClient .fetch (uri ).toCompletableFuture ()::join );
183180
184181 assertTrue (err .getCause () instanceof AccessGrantException );
185182 }
186183
187184 @ Test
188185 void testFetchNotFound () {
189186 final URI uri = URIBuilder .newBuilder (baseUri ).path ("not-found" ).build ();
190- final AccessGrantClient client = new AccessGrantClient (uri );
191187 final CompletionException err1 = assertThrows (CompletionException .class ,
192- client .fetch (uri ).toCompletableFuture ()::join );
188+ agClient .fetch (uri ).toCompletableFuture ()::join );
193189
194190 assertTrue (err1 .getCause () instanceof AccessGrantException );
195191
196192 final URI agent = URI .create ("https://id.test/agent" );
197193
198194 final CompletionException err2 = assertThrows (CompletionException .class ,
199- client .issue (ACCESS_GRANT , agent , Collections .emptySet (), Collections .emptySet (),
195+ agClient .issue (ACCESS_GRANT , agent , Collections .emptySet (), Collections .emptySet (),
200196 Collections .emptySet (), Instant .now ()).toCompletableFuture ()::join );
201197 assertTrue (err2 .getCause () instanceof AccessGrantException );
202198 }
@@ -209,8 +205,7 @@ void testIssueGrant() {
209205 claims .put ("iss" , ISS );
210206 claims .put ("azp" , AZP );
211207 final String token = generateIdToken (claims );
212- final AccessGrantClient client = new AccessGrantClient (baseUri )
213- .session (OpenIdSession .ofIdToken (token ));
208+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
214209
215210 final URI agent = URI .create ("https://id.test/agent" );
216211 final Instant expiration = Instant .parse ("2022-08-27T12:00:00Z" );
@@ -238,8 +233,7 @@ void testIssueRequest() {
238233 claims .put ("iss" , ISS );
239234 claims .put ("azp" , AZP );
240235 final String token = generateIdToken (claims );
241- final AccessGrantClient client = new AccessGrantClient (baseUri )
242- .session (OpenIdSession .ofIdToken (token ));
236+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
243237
244238 final URI agent = URI .create ("https://id.test/agent" );
245239 final Instant expiration = Instant .parse ("2022-08-27T12:00:00Z" );
@@ -261,16 +255,14 @@ void testIssueRequest() {
261255
262256 @ Test
263257 void testIssueNoAuth () {
264- final AccessGrantClient client = new AccessGrantClient (baseUri );
265-
266258 final URI agent = URI .create ("https://id.test/agent" );
267259 final Instant expiration = Instant .parse ("2022-08-27T12:00:00Z" );
268260 final Set <String > modes = new HashSet <>(Arrays .asList ("Read" , "Append" ));
269261 final Set <String > purposes = Collections .singleton ("https://purpose.test/Purpose1" );
270262
271263 final Set <URI > resources = Collections .singleton (URI .create ("https://storage.test/data/" ));
272264 final CompletionException err = assertThrows (CompletionException .class , () ->
273- client .issue (ACCESS_GRANT , agent , resources , modes , purposes , expiration )
265+ agClient .issue (ACCESS_GRANT , agent , resources , modes , purposes , expiration )
274266 .toCompletableFuture ().join ());
275267 assertTrue (err .getCause () instanceof AccessGrantException );
276268 }
@@ -283,8 +275,7 @@ void testIssueOther() {
283275 claims .put ("iss" , ISS );
284276 claims .put ("azp" , AZP );
285277 final String token = generateIdToken (claims );
286- final AccessGrantClient client = new AccessGrantClient (baseUri )
287- .session (OpenIdSession .ofIdToken (token ));
278+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
288279
289280 final URI agent = URI .create ("https://id.test/agent" );
290281 final Instant expiration = Instant .parse ("2022-08-27T12:00:00Z" );
@@ -306,8 +297,7 @@ void testQueryGrant() {
306297 claims .put ("iss" , ISS );
307298 claims .put ("azp" , AZP );
308299 final String token = generateIdToken (claims );
309- final AccessGrantClient client = new AccessGrantClient (baseUri )
310- .session (OpenIdSession .ofIdToken (token ));
300+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
311301
312302 final List <AccessGrant > grants = client .query (URI .create ("SolidAccessGrant" ), null ,
313303 URI .create ("https://storage.example/e973cc3d-5c28-4a10-98c5-e40079289358/a/b/c" ), "Read" )
@@ -323,8 +313,7 @@ void testQueryRequest() {
323313 claims .put ("iss" , ISS );
324314 claims .put ("azp" , AZP );
325315 final String token = generateIdToken (claims );
326- final AccessGrantClient client = new AccessGrantClient (baseUri )
327- .session (OpenIdSession .ofIdToken (token ));
316+ final AccessGrantClient client = agClient .session (OpenIdSession .ofIdToken (token ));
328317
329318 final List <AccessGrant > grants = client .query (URI .create ("SolidAccessRequest" ), null ,
330319 URI .create ("https://storage.example/f1759e6d-4dda-4401-be61-d90d070a5474/a/b/c" ), "Read" )
@@ -334,10 +323,8 @@ void testQueryRequest() {
334323
335324 @ Test
336325 void testQueryInvalidAuth () {
337- final AccessGrantClient client = new AccessGrantClient (baseUri );
338-
339326 final CompletionException err = assertThrows (CompletionException .class ,
340- client .query (URI .create ("SolidAccessGrant" ), null , null , null ).toCompletableFuture ()::join );
327+ agClient .query (URI .create ("SolidAccessGrant" ), null , null , null ).toCompletableFuture ()::join );
341328
342329 assertTrue (err .getCause () instanceof AccessGrantException );
343330 }
0 commit comments