Search in sources :

Example 1 with DataStoreOperations

use of nl.knaw.huygens.timbuctoo.core.DataStoreOperations in project timbuctoo by HuygensING.

the class ChangeListenerTest method callsOnRemoveFromCollectionOnDeleteEntity.

@Test
public void callsOnRemoveFromCollectionOnDeleteEntity() throws Exception {
    ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
        assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
        Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
        assertThat(prevVersions, is(1L));
    });
    UUID id = UUID.randomUUID();
    ChangeListener spy = spy(changeListener);
    DataStoreOperations instance = forDeleteCall(spy, id, 1, "someName");
    Collection collection = mock(Collection.class);
    when(collection.getEntityTypeName()).thenReturn("someName");
    when(collection.getVre()).thenReturn(mock(Vre.class));
    instance.deleteEntity(collection, id, new Change());
    verify(spy).onRemoveFromCollection(same(collection), any(), any());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with DataStoreOperations

use of nl.knaw.huygens.timbuctoo.core.DataStoreOperations in project timbuctoo by HuygensING.

the class ChangeListenerTest method callsOnPropertyUpdateOnReplaceEntity.

@Test
public void callsOnPropertyUpdateOnReplaceEntity() throws Exception {
    ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
        assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
        Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
        assertThat(prevVersions, is(1L));
    });
    UUID id = UUID.randomUUID();
    ChangeListener spy = spy(changeListener);
    DataStoreOperations instance = forReplaceCall(spy, id, 1);
    UpdateEntity updateEntity = new UpdateEntity(id, newArrayList(), 1);
    updateEntity.setModified(new Change());
    Collection collectionMock = mock(Collection.class);
    instance.replaceEntity(collectionMock, updateEntity);
    verify(spy).onPropertyUpdate(same(collectionMock), any(), any());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 3 with DataStoreOperations

use of nl.knaw.huygens.timbuctoo.core.DataStoreOperations in project timbuctoo by HuygensING.

the class TimbuctooActionsAddPidTest method setup.

@Before
public void setup() throws Exception {
    dataStoreOperations = mock(DataStoreOperations.class);
    instance = new TimbuctooActions(null, null, null, (coll, id, rev) -> URI.create("http://example.org/persistent"), dataStoreOperations, null);
    id = UUID.randomUUID();
    pidUri = new URI("http://example.com/pid");
}
Also used : Mockito.doThrow(org.mockito.Mockito.doThrow) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) ImmutableEntityLookup(nl.knaw.huygens.timbuctoo.core.dto.ImmutableEntityLookup) Test(org.junit.Test) NotFoundException(nl.knaw.huygens.timbuctoo.core.NotFoundException) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) URI(java.net.URI) UUID(java.util.UUID) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) TimbuctooActions(nl.knaw.huygens.timbuctoo.core.TimbuctooActions) DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) URI(java.net.URI) Before(org.junit.Before)

Example 4 with DataStoreOperations

use of nl.knaw.huygens.timbuctoo.core.DataStoreOperations in project timbuctoo by HuygensING.

the class ChangeListenerTest method callsOnAddToCollectionOnReplaceEntityWithNewCollection.

@Test
public void callsOnAddToCollectionOnReplaceEntityWithNewCollection() throws Exception {
    ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
        assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
        Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
        assertThat(prevVersions, is(1L));
    });
    UUID id = UUID.randomUUID();
    ChangeListener spy = spy(changeListener);
    DataStoreOperations instance = forReplaceCall(spy, id, 1);
    UpdateEntity updateEntity = new UpdateEntity(id, newArrayList(), 1);
    updateEntity.setModified(new Change());
    Collection collectionMock = mock(Collection.class);
    given(collectionMock.getEntityTypeName()).willReturn("something");
    instance.replaceEntity(collectionMock, updateEntity);
    verify(spy).onAddToCollection(same(collectionMock), any(), any());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with DataStoreOperations

use of nl.knaw.huygens.timbuctoo.core.DataStoreOperations in project timbuctoo by HuygensING.

the class LoadSaveVreTest method save.

private List<Vertex> save(Vre vre, Tuple<DataStoreOperations, Graph> dataAccess) {
    DataStoreOperations db = dataAccess.getLeft();
    db.saveVre(vre);
    db.success();
    return dataAccess.getRight().traversal().V().toList();
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations)

Aggregations

DataStoreOperations (nl.knaw.huygens.timbuctoo.core.DataStoreOperations)6 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)5 Test (org.junit.Test)5 UUID (java.util.UUID)4 Change (nl.knaw.huygens.timbuctoo.model.Change)3 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)2 URI (java.net.URI)1 NotFoundException (nl.knaw.huygens.timbuctoo.core.NotFoundException)1 TimbuctooActions (nl.knaw.huygens.timbuctoo.core.TimbuctooActions)1 ImmutableEntityLookup (nl.knaw.huygens.timbuctoo.core.dto.ImmutableEntityLookup)1 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)1 Before (org.junit.Before)1 Mockito.doThrow (org.mockito.Mockito.doThrow)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1