use of uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate in project Gaffer by gchq.
the class AddNamedViewHandlerTest method shouldAddNamedViewCorrectly.
@Test
public void shouldAddNamedViewCorrectly() throws OperationException, CacheOperationFailedException {
handler.doOperation(addNamedView, context, store);
final NamedViewDetail result = namedViewCache.getNamedView(testNamedViewName);
assertTrue(cacheContains(testNamedViewName));
assertEquals(addNamedView.getName(), result.getName());
assertEquals(new String(addNamedView.getView().toCompactJson()), result.getView());
assertEquals(context.getUser().getUserId(), result.getCreatorId());
assertEquals(new UnrestrictedAccessPredicate(), result.getOrDefaultReadAccessPredicate());
final AccessPredicate expectedWriteAccessPredicate = new NamedViewWriteAccessPredicate(context.getUser(), Arrays.asList(writeAccessRoles));
assertEquals(expectedWriteAccessPredicate, result.getOrDefaultWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate in project Gaffer by gchq.
the class NamedViewDetailTest method shouldCreatePredicatesIfNotSpecifiedInJson.
@Test
public void shouldCreatePredicatesIfNotSpecifiedInJson() throws IOException {
// Given
final String json = String.format("{%n" + " \"name\" : \"view1\",%n" + " \"description\" : \"description\",%n" + " \"creatorId\" : \"creator\",%n" + " \"writeAccessRoles\" : [ \"writeAuth1\", \"writeAuth2\" ],%n" + " \"parameters\" : {%n" + " \"entityGroup\" : {%n" + " \"description\" : \"some description\",%n" + " \"defaultValue\" : \"red\",%n" + " \"valueClass\" : \"java.lang.String\",%n" + " \"required\" : false%n" + " }%n" + " },%n" + " \"view\" : \"{\\\"entities\\\": {\\\"${entityGroup}\\\":{}}}\",%n" + " \"readAccessPredicate\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.access.predicate.AccessPredicate\",%n" + " \"userPredicate\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate\"%n" + " }%n" + " }%n" + "}%n");
// When
NamedViewDetail deserialised = JsonSerialiser.deserialise(json, NamedViewDetail.class);
// Then
AccessPredicate expected = new NamedViewWriteAccessPredicate("creator", asList("writeAuth1", "writeAuth2"));
assertEquals(expected, deserialised.getOrDefaultWriteAccessPredicate());
}
use of uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate in project Gaffer by gchq.
the class NamedViewDetailTest method shouldConfigureDefaultAccessPredicateForWriteAccessTestByDefault.
@Test
public void shouldConfigureDefaultAccessPredicateForWriteAccessTestByDefault() {
final List<String> writers = asList("writeAuth1", "writeAuth2");
final NamedViewDetail namedViewDetail = createNamedViewDetailBuilder().writers(writers).build();
assertEquals(new NamedViewWriteAccessPredicate(new User.Builder().userId("creator").build(), writers), namedViewDetail.getOrDefaultWriteAccessPredicate());
}
Aggregations