Search in sources :

Example 51 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method getFieldDefinitionReturnsNullIfUserHasNoPermission.

@Test
public void getFieldDefinitionReturnsNullIfUserHasNoPermission() throws Exception {
    final DataSetRepository dataSetRepository = mock(DataSetRepository.class);
    DataSet dataSet = createDataSetWithUserPermissions("user__dataSetUserHasAccessTo", Sets.newHashSet(Permission.READ));
    DataSet dataSet2 = createDataSetWithUserPermissions("user__dataSetUserDoesNotHasAccessTo", Sets.newHashSet());
    Collection<DataSet> dataSetCollection = Sets.newHashSet(dataSet, dataSet2);
    given(dataSetRepository.getDataSets()).willReturn(dataSetCollection);
    final PermissionBasedFieldVisibility permissionBasedFieldVisibility = new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository);
    final GraphQLFieldsContainer graphQlFieldsContainer = createGraphQlFieldsContainer("user__dataSetUserHasAccessTo", "user__dataSetUserDoesNotHasAccessTo");
    GraphQLFieldDefinition retrievedGraphQlFieldDefinition = permissionBasedFieldVisibility.getFieldDefinition(graphQlFieldsContainer, "user__dataSetUserDoesNotHasAccessTo");
    assertThat(retrievedGraphQlFieldDefinition, is(nullValue()));
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Test(org.junit.Test)

Example 52 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo.

@Test
public void getFieldDefinitionsShowsOnlyDataSetsThatUserHasAccessTo() throws Exception {
    final DataSetRepository dataSetRepository = mock(DataSetRepository.class);
    DataSet dataSet = createDataSetWithUserPermissions("user__dataSetUserHasAccessTo", Sets.newHashSet(Permission.READ));
    DataSet dataSet2 = createDataSetWithUserPermissions("user__dataSetUserDoesNotHasAccessTo", Sets.newHashSet());
    Collection<DataSet> dataSetCollection = Sets.newHashSet(dataSet, dataSet2);
    given(dataSetRepository.getDataSets()).willReturn(dataSetCollection);
    final PermissionBasedFieldVisibility permissionBasedFieldVisibility = new PermissionBasedFieldVisibility(userPermissionCheck, dataSetRepository);
    final GraphQLFieldsContainer graphQlFieldsContainer = createGraphQlFieldsContainer("user__dataSetUserHasAccessTo", "user__dataSetUserDoesNotHasAccessTo");
    List<GraphQLFieldDefinition> retrievedGraphQlFieldDefinitions = permissionBasedFieldVisibility.getFieldDefinitions(graphQlFieldsContainer);
    assertThat(retrievedGraphQlFieldDefinitions, contains(hasProperty("name", is("user__dataSetUserHasAccessTo"))));
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) GraphQLFieldsContainer(graphql.schema.GraphQLFieldsContainer) Test(org.junit.Test)

Example 53 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method createDataSetWithUserPermissions.

private DataSet createDataSetWithUserPermissions(String combinedId, Set<Permission> permissions) {
    DataSetMetaData dataSetMetaData = createDataSetMetadata(combinedId);
    given(userPermissionCheck.getPermissions(dataSetMetaData)).willReturn(permissions);
    return createDataSet(dataSetMetaData);
}
Also used : DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) BasicDataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.BasicDataSetMetaData)

Example 54 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class PermissionBasedFieldVisibilityTest method createDataSet.

private DataSet createDataSet(DataSetMetaData dataSetMetaData) {
    DataSet dataSet = mock(DataSet.class);
    given(dataSet.getMetadata()).willReturn(dataSetMetaData);
    return dataSet;
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)

Example 55 with DataSet

use of nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet in project timbuctoo by HuygensING.

the class RsDocumentBuilderTest method init.

@Before
public void init() throws Exception {
    dataSetRepository = mock(DataSetRepository.class);
    rsDocumentBuilder = new RsDocumentBuilder(dataSetRepository, new UriHelper(URI.create("http://example.com")));
    dataSet = mock(DataSet.class);
    DataSetMetaData dataSetMetaData1 = mock(DataSetMetaData.class);
    DataSetMetaData dataSetMetaData2 = mock(DataSetMetaData.class);
    when(dataSetMetaData1.getOwnerId()).thenReturn("u1");
    when(dataSetMetaData1.getDataSetId()).thenReturn("ds1");
    when(dataSetMetaData2.getOwnerId()).thenReturn("u2");
    when(dataSetMetaData2.getDataSetId()).thenReturn("ds2");
    when(dataSet.getMetadata()).thenReturn(dataSetMetaData1).thenReturn(dataSetMetaData2);
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) DataSetRepository(nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository) UriHelper(nl.knaw.huygens.timbuctoo.util.UriHelper) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) Before(org.junit.Before)

Aggregations

DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)44 DataSetRepository (nl.knaw.huygens.timbuctoo.v5.dataset.DataSetRepository)12 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)12 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)12 Test (org.junit.Test)12 IOException (java.io.IOException)11 LogStorageFailedException (nl.knaw.huygens.timbuctoo.v5.filestorage.exceptions.LogStorageFailedException)11 Map (java.util.Map)10 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)7 GraphQLFieldsContainer (graphql.schema.GraphQLFieldsContainer)7 List (java.util.List)7 Optional (java.util.Optional)7 ExecutionException (java.util.concurrent.ExecutionException)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 ImportManager (nl.knaw.huygens.timbuctoo.v5.dataset.ImportManager)6 ImportStatus (nl.knaw.huygens.timbuctoo.v5.dataset.ImportStatus)6 DataStoreCreationException (nl.knaw.huygens.timbuctoo.v5.dataset.exceptions.DataStoreCreationException)6