Skip to content

Commit ddf637b

Browse files
committed
Test merge method
1 parent f25c2cb commit ddf637b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

acp/src/main/java/com/inrupt/client/acp/AccessControlResource.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,17 +208,19 @@ public void compact() {
208208
/**
209209
* Merge two or more policies into a single policies with combined matchers.
210210
*
211+
* @param allow the modes to allow
211212
* @param policies the policies to merge
212213
* @return the merged policy
213214
*/
214-
public Policy merge(final Policy... policies) {
215+
public Policy merge(final Set<URI> allow, final Policy... policies) {
215216
final var baseUri = getIdentifier().getScheme() + ":" + getIdentifier().getSchemeSpecificPart();
216217
final var policy = new Policy(asIRI(baseUri + "#" + UUID.randomUUID()), getGraph());
217218
for (final var p : policies) {
218219
policy.allOf().addAll(p.allOf());
219220
policy.anyOf().addAll(p.anyOf());
220221
policy.noneOf().addAll(p.noneOf());
221222
}
223+
policy.allow().addAll(allow);
222224
return policy;
223225
}
224226

acp/src/test/java/com/inrupt/client/acp/AccessControlResourceTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,22 @@ void expandAcr4Async() {
354354
}
355355
}).toCompletableFuture().join();
356356
}
357+
358+
@Test
359+
void testMerge() {
360+
final var identifier = "https://data.example/resource";
361+
final var agent = URI.create("https://id.example/agent");
362+
final var client = URI.create("https://app.example/id");
363+
364+
final var acr = new AccessControlResource(URI.create(identifier), rdf.createDataset());
365+
final var policy = acr.merge(Set.of(ACL.Read, ACL.Write), acr.agentPolicy(agent), acr.clientPolicy(client));
366+
367+
assertEquals(2, policy.allow().size());
368+
assertTrue(policy.allow().contains(ACL.Read));
369+
assertTrue(policy.allow().contains(ACL.Write));
370+
371+
assertEquals(2, policy.allOf().size());
372+
assertEquals(0, policy.anyOf().size());
373+
assertEquals(0, policy.noneOf().size());
374+
}
357375
}

0 commit comments

Comments
 (0)