ConsumerPrincipal extends Principal { public Consumer getConsumer() { return consumer; } ConsumerPrincipal(Consumer consumer, Owner owner); Consumer getConsumer(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String getName(); @Override String getType(); @Override boolean hasFullAccess();  }
@Test public void getConsumer() { assertTrue(principal.getConsumer().equals(consumer)); }
@Test public void accessToConsumerEntitlement() { Consumer c = mock(Consumer.class); when(c.getUuid()).thenReturn("consumer-uuid"); Entitlement e = mock(Entitlement.class); when(e.getConsumer()).thenReturn(c); assertTrue(principal.canAccess(e, SubResource.NONE, Access.ALL)); }
@Test public void accessToMultipleConsumerEntitlements() { Consumer c = mock(Consumer.class); when(c.getUuid()).thenReturn("consumer-uuid"); List<Entitlement> entitlements = new ArrayList<>(); for (int i = 0; i < 5; i++) { Entitlement e = mock(Entitlement.class); when(e.getConsumer()).thenReturn(c); entitlements.add(e); } assertTrue(principal.canAccessAll(entitlements, SubResource.NONE, Access.ALL)); }
@Test public void denyAccessToOtherConsumerEntitlements() { Consumer c = mock(Consumer.class); Consumer c0 = mock(Consumer.class); when(c.getUuid()).thenReturn("consumer-uuid"); when(c0.getUuid()).thenReturn("consumer-0-uuid"); List<Entitlement> entitlements = new ArrayList<>(); for (int i = 0; i < 5; i++) { Entitlement e = mock(Entitlement.class); if (i == 3) { when(e.getConsumer()).thenReturn(c0); } else { when(e.getConsumer()).thenReturn(c); } entitlements.add(e); } assertFalse(principal.canAccessAll(entitlements, SubResource.NONE, Access.ALL)); }