use of com.google.gerrit.server.permissions.PermissionBackendCondition in project gerrit by GerritCodeReview.
the class UiActionsTest method permissionBackendConditionEvaluationDeduplicatesAndBackfills.
@Test
public void permissionBackendConditionEvaluationDeduplicatesAndBackfills() throws Exception {
FakeForProject forProject = new FakeForProject();
// Create three conditions, two of which are identical
PermissionBackendCondition cond1 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
PermissionBackendCondition cond2 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.READ);
PermissionBackendCondition cond3 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
// Set up the Mock to expect a call of bulkEvaluateTest to only contain cond{1,2} since cond3
// needs to be identified as duplicate and not called out explicitly.
PermissionBackend permissionBackendMock = mock(PermissionBackend.class);
UiActions.evaluatePermissionBackendConditions(permissionBackendMock, ImmutableList.of(cond1, cond2, cond3));
// Disallow queries for value to ensure that cond3 (previously left behind) is backfilled with
// the value of cond1 and issues no additional call to PermissionBackend.
forProject.disallowValueQueries();
verify(permissionBackendMock, only()).bulkEvaluateTest(ImmutableSet.of(cond1, cond2));
// Assert the values of all conditions
assertThat(cond1.value()).isFalse();
assertThat(cond2.value()).isTrue();
assertThat(cond3.value()).isFalse();
}
use of com.google.gerrit.server.permissions.PermissionBackendCondition in project gerrit by GerritCodeReview.
the class UiActions method evaluatePermissionBackendConditions.
@VisibleForTesting
static void evaluatePermissionBackendConditions(PermissionBackend perm, List<PermissionBackendCondition> conds) {
Map<PermissionBackendCondition, PermissionBackendCondition> dedupedConds = new HashMap<>(conds.size());
for (PermissionBackendCondition cond : conds) {
dedupedConds.put(cond, cond);
}
perm.bulkEvaluateTest(dedupedConds.keySet());
for (PermissionBackendCondition cond : conds) {
cond.set(dedupedConds.get(cond).value());
}
}
Aggregations