Search in sources :

Example 1 with NamedViewWriteAccessPredicate

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());
}
Also used : UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 2 with NamedViewWriteAccessPredicate

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());
}
Also used : NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) AccessPredicate(uk.gov.gchq.gaffer.access.predicate.AccessPredicate) UnrestrictedAccessPredicate(uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate) NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) Test(org.junit.jupiter.api.Test)

Example 3 with NamedViewWriteAccessPredicate

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());
}
Also used : NamedViewWriteAccessPredicate(uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)3 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)2 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)2 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)1