@Test void testUpdate() { Package pack = mock(Package.class); Package parent = mock(Package.class); Package oldPack = mock(Package.class); when(pack.getId()).thenReturn("1"); when(parent.getId()).thenReturn("2"); when(pack.getParent()).thenReturn(parent); when(oldPack.getParent()).thenReturn(parent); when(oldPack.getId()).thenReturn("1"); MutableAcl acl = mock(MutableAcl.class); MutableAcl parentAcl = mock(MutableAcl.class); doReturn(true).when(userPermissionEvaluator).hasPermission(new PackageIdentity("1"), UPDATE); when(mutableAclService.readAclById(any())) .thenAnswer( invocation -> { Object argument = invocation.getArguments()[0]; if (argument.equals(new PackageIdentity("1"))) { return acl; } else if (argument.equals(new PackageIdentity("2"))) { return parentAcl; } return null; }); when(delegateRepository.findOneById(pack.getId())).thenReturn(oldPack); repo.update(pack); verify(mutableAclService).updateAcl(acl); verify(delegateRepository).update(pack); }
@Override public void update(Package pack) { if (!isActionPermitted(pack, UPDATE)) { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } throwPermissionException(pack, UPDATE); } delegate().update(pack); updateAcl(pack); }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void update(Package pack) { if (!isActionPermitted(pack, UPDATE)) { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } throwPermissionException(pack, UPDATE); } delegate().update(pack); updateAcl(pack); } }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void update(Package pack) { if (!isActionPermitted(pack, UPDATE)) { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } throwPermissionException(pack, UPDATE); } delegate().update(pack); updateAcl(pack); } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void update(Package pack) { if (!isActionPermitted(pack, UPDATE)) { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } throwPermissionException(pack, UPDATE); } delegate().update(pack); updateAcl(pack); } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); @Override boolean isActionPermitted(Package updatedPack, Action action); @Override boolean isActionPermitted(Object id, Action action); @Override void throwPermissionException(Package pack, Action action); @Override Package findOneById(Object id); @Override void add(Package pack); @Override void update(Package pack); @Override Integer add(Stream<Package> packages); @Override void createAcl(Package pack); @Override void deleteAcl(Object id); @Override void deleteAcl(Package pack); @Override void updateAcl(Package pack); }
PackageRepositorySecurityDecorator extends AbstractRowLevelSecurityRepositoryDecorator<Package> { @Override public void update(Package pack) { if (!isActionPermitted(pack, UPDATE)) { if (pack.getParent() == null) { throw new NullParentPackageNotSuException(); } throwPermissionException(pack, UPDATE); } delegate().update(pack); updateAcl(pack); } PackageRepositorySecurityDecorator(
      Repository<Package> delegateRepository,
      MutableAclService mutableAclService,
      UserPermissionEvaluator userPermissionEvaluator); @Override boolean isActionPermitted(Package updatedPack, Action action); @Override boolean isActionPermitted(Object id, Action action); @Override void throwPermissionException(Package pack, Action action); @Override Package findOneById(Object id); @Override void add(Package pack); @Override void update(Package pack); @Override Integer add(Stream<Package> packages); @Override void createAcl(Package pack); @Override void deleteAcl(Object id); @Override void deleteAcl(Package pack); @Override void updateAcl(Package pack);  }