use of uk.gov.gchq.koryphe.impl.function.CallMethod in project Gaffer by gchq.
the class FederatedAccessAuthTest method shouldSerialiseAndDeserialiseAccessPredicatesToJson.
@Test
public void shouldSerialiseAndDeserialiseAccessPredicatesToJson() throws SerialisationException {
// Given
final FederatedAccess federatedAccess = new FederatedAccess.Builder().addingUserId(AUTH_USER_ID).isPublic(false).readAccessPredicate(new AccessPredicate(new AdaptedPredicate(new CallMethod("getDataAuths"), new CollectionContains(ALL_USERS)))).writeAccessPredicate(new AccessPredicate(new AdaptedPredicate(new CallMethod("getDataAuths"), new CollectionContains(AUTH_1)))).build();
// When
final String serialised = new String(JSONSerialiser.serialise(federatedAccess));
// Then
final String expected = "{" + " \"addingUserId\": \"authUser\"," + " \"disabledByDefault\": false," + " \"public\": false," + " \"readAccessPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + " \"userPredicate\": {" + " \"class\": \"uk.gov.gchq.koryphe.predicate.AdaptedPredicate\"," + " \"inputAdapter\": {" + " \"class\": \"uk.gov.gchq.koryphe.impl.function.CallMethod\"," + " \"method\": \"getDataAuths\"" + " }," + " \"predicate\": {" + " \"class\": \"uk.gov.gchq.koryphe.impl.predicate.CollectionContains\"," + " \"value\": \"allUsers\"" + " }" + " }" + " }," + " \"writeAccessPredicate\": {" + " \"class\": \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\"," + " \"userPredicate\": {" + " \"class\": \"uk.gov.gchq.koryphe.predicate.AdaptedPredicate\"," + " \"inputAdapter\": {" + " \"class\": \"uk.gov.gchq.koryphe.impl.function.CallMethod\"," + " \"method\": \"getDataAuths\"" + " }," + " \"predicate\": {" + " \"class\": \"uk.gov.gchq.koryphe.impl.predicate.CollectionContains\"," + " \"value\": \"auth1\"" + " }" + " }" + " }" + "}";
JsonAssert.assertEquals(expected, serialised);
final FederatedAccess deserialised = JSONSerialiser.deserialise(serialised, FederatedAccess.class);
assertEquals(federatedAccess, deserialised);
}
use of uk.gov.gchq.koryphe.impl.function.CallMethod in project Gaffer by gchq.
the class FederatedAddGraphWithHooksHandlerTest method shouldAddGraphWithCustomReadAccessPredicate.
@Test
public void shouldAddGraphWithCustomReadAccessPredicate() throws Exception {
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
final Schema expectedSchema = new Schema.Builder().build();
assertEquals(0, store.getGraphs(testUser, null, ignore).size());
final AccessPredicate allowBlankUserAndTestUserReadAccess = new AccessPredicate(new AdaptedPredicate(new CallMethod("getUserId"), new Or<>(new IsEqual(testUser.getUserId()), new IsEqual(blankUser.getUserId()))));
new FederatedAddGraphWithHooksHandler().doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).readAccessPredicate(allowBlankUserAndTestUserReadAccess).build(), new Context(testUser), store);
assertEquals(1, store.getGraphs(blankUser, null, ignore).size());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
}
Aggregations